-
Notifications
You must be signed in to change notification settings - Fork 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
feature: allow ngx.sleep to be used blockingly in non-yieldable phases #1759
base: master
Are you sure you want to change the base?
Conversation
Allow ngx.sleep everywhere simplify the application's logic. Now we don't need to write a fallback if the same function need to be run in non-yieldable phases. Close openresty#1730.
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.
should we have a different log format for sleep in non NGX_HTTP_LUA_CONTEXT_YIELDABLE
? Or we could log with phase in the debug log?
@rainingmaster @dndx |
|
||
Sleeps for the specified seconds without blocking. One can specify time resolution up to 0.001 seconds (i.e., one millisecond). | ||
Sleeps for the specified seconds without blocking in yieldable phases or blockingly in other phases. |
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.
we'd better clarify the blockingly phases.
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.
and we need to highlight it's not recommended to use it in the non-yieldable phase since it will block the whole nginx worker process.
@@ -5621,14 +5621,17 @@ ngx.sleep | |||
|
|||
**syntax:** *ngx.sleep(seconds)* | |||
|
|||
**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua** | |||
**context:** *init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, exit_worker_by_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.
It's not safe to use blocking sleeps in certain contexts like init_worker_by_lua*
, set_by_lua*
, header_filter_by_lua*
, and etc.
I'm fine with enabling it in contexts where blocking operations do not matter, like in init_by_lua*
and exit_worker_by_lua*
. Otherwise it's too dangerous.
This pull request is now in conflict :( |
f924579
to
fef2581
Compare
This pull request is now in conflict :( |
This pull request is now in conflict :( |
This pull request is now in conflict :( |
This pull request is now in conflict :( |
This pull request is now in conflict :( |
Allow ngx.sleep everywhere simplify the application's logic.
Now we don't need to write a fallback if the same function need to be
run in non-yieldable phases.
Close #1730.
I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.