-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lua randomseed per worker #3581
lua randomseed per worker #3581
Conversation
lgtm 👍 |
@@ -0,0 +1,9 @@ | |||
describe("lua_ingress", function() | |||
it("patches math.randomseed to not be caled more than once per worker", function() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
caled -> called
|
||
std = { | ||
read_globals = { math = { fields = { "randomseed" } } } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file needs to be rewritten to something like:
std = {
globals = {'_TEST', 'ngx_lua'},
read_globals = { math = { fields = { "randomseed" } } }
}
exclude_files = {'./rootfs/etc/nginx/lua/test/**/*.lua'}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zrdaley it looks like globals, read_globals, std are all same level, so can not be nested like you suggested. I had to use ignore per file.
bafd553
to
1666fdc
Compare
@@ -3,3 +3,8 @@ globals = { | |||
'_TEST' | |||
} | |||
exclude_files = {'./rootfs/etc/nginx/lua/test/**/*.lua'} | |||
files["rootfs/etc/nginx/lua/lua_ingress.lua"] = { | |||
ignore = { "122" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is taken from
rootfs/etc/nginx/lua/lua_ingress.lua:5:1: (W122) setting read-only field randomseed of global math
1666fdc
to
2f4d9ba
Compare
2f4d9ba
to
4896b06
Compare
/assign @aledbf |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aledbf, ElvinEfendi The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
Previously we have switched to explicitly seeding PRNG for tests and this PR does it for production code. I've also patched
math.randomseed
so that individual modules can not re-seed PRNG since that can potentially affect randomness. And the reason why I'm seeding per worker rather than ininit_by_lua
is because otherwise every worker would be seeded with the same seed.lua_ingress.lua
will be used for general things such as this. And eventually I'd like it to be the only entry point to Lua code that executes everything else.Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close that issue when PR gets merged): fixes #Special notes for your reviewer: