Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

spacewander
Copy link
Member

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.

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.
Copy link
Member

@rainingmaster rainingmaster left a 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?

src/ngx_http_lua_sleep.c Outdated Show resolved Hide resolved
@spacewander
Copy link
Member Author

@rainingmaster @dndx
Updated.


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.
Copy link
Member

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.

Copy link
Member

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**
Copy link
Member

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.

@mergify
Copy link

mergify bot commented Sep 20, 2021

This pull request is now in conflict :(

@mergify
Copy link

mergify bot commented Mar 20, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Mar 20, 2023
@mergify mergify bot removed the conflict label May 10, 2023
@mergify
Copy link

mergify bot commented May 10, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label May 10, 2023
@mergify mergify bot removed the conflict label Sep 23, 2023
@mergify
Copy link

mergify bot commented Sep 23, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Sep 23, 2023
@mergify mergify bot removed the conflict label Mar 6, 2024
Copy link

mergify bot commented Mar 6, 2024

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Mar 6, 2024
@mergify mergify bot removed the conflict label May 27, 2024
Copy link

mergify bot commented May 27, 2024

This pull request is now in conflict :(

@mergify mergify bot added the conflict label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: allow ngx.sleep to be used everywhere
5 participants