feature: allow ngx.sleep to be used blockingly in non-yieldable phases#1759
feature: allow ngx.sleep to be used blockingly in non-yieldable phases#1759spacewander wants to merge 2 commits intoopenresty:masterfrom
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.
rainingmaster
left a comment
There was a problem hiding this comment.
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 |
| '''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*'' | ||
|
|
||
| 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.
we'd better clarify the blockingly phases.
There was a problem hiding this comment.
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.
| **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.
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 :( |
|
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.