-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66aecbd
commit 4896b06
Showing
6 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ fi | |
|
||
hack/verify-all.sh | ||
|
||
luacheck -q rootfs/etc/nginx/lua/ | ||
luacheck --codes -q rootfs/etc/nginx/lua/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
local _M = {} | ||
|
||
local seeds = {} | ||
local original_randomseed = math.randomseed | ||
math.randomseed = function(seed) | ||
local pid = ngx.worker.pid() | ||
|
||
if seeds[pid] then | ||
ngx.log(ngx.WARN, | ||
string.format("ignoring math.randomseed(%d) since PRNG is already seeded for worker %d", seed, pid)) | ||
return | ||
end | ||
|
||
original_randomseed(seed) | ||
seeds[pid] = seed | ||
end | ||
|
||
local function randomseed() | ||
math.randomseed(ngx.time() + ngx.worker.pid()) | ||
end | ||
|
||
function _M.init_worker() | ||
randomseed() | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe("lua_ingress", function() | ||
it("patches math.randomseed to not be called more than once per worker", function() | ||
local s = spy.on(ngx, "log") | ||
|
||
math.randomseed(100) | ||
assert.spy(s).was_called_with(ngx.WARN, | ||
string.format("ignoring math.randomseed(%d) since PRNG is already seeded for worker %d", 100, ngx.worker.pid())) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters