Skip to content

Commit e718d79

Browse files
committed
chore: check context in ngx.timer.* for exit process
1 parent b721656 commit e718d79

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

README.markdown

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,9 +3154,10 @@ The directive is supported when using OpenSSL 1.0.2 or higher and nginx 1.19.4 o
31543154

31553155
Several `lua_ssl_conf_command` directives can be specified on the same level:
31563156

3157-
```
3158-
lua_ssl_conf_command Options PrioritizeChaCha;
3159-
lua_ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;
3157+
```nginx
3158+
3159+
lua_ssl_conf_command Options PrioritizeChaCha;
3160+
lua_ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;
31603161
```
31613162

31623163
Configuration commands are applied after OpenResty own configuration for SSL, so they can be used to override anything set by OpenResty.
@@ -3165,6 +3166,8 @@ Note though that configuring OpenSSL directly with `lua_ssl_conf_command` might
31653166

31663167
This directive was first introduced in the `v0.10.21` release.
31673168

3169+
3170+
31683171
[Back to TOC](#directives)
31693172

31703173
lua_http10_buffering
@@ -8405,7 +8408,7 @@ ngx.timer.at
84058408

84068409
**syntax:** *hdl, err = ngx.timer.at(delay, callback, user_arg1, user_arg2, ...)*
84078410

8408-
**context:** *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**
8411+
**context:** *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**
84098412

84108413
Creates an Nginx timer with a user callback function as well as optional user arguments.
84118414

@@ -8539,6 +8542,8 @@ table. It won't share the same `ngx.ctx` with the Lua handler creating the timer
85398542
If you need to pass data from the timer creator to the timer handler, please
85408543
use the extra parameters of `ngx.timer.at()`.
85418544

8545+
Since nginx has been confirmed that all timers have been cleaned up when exit worker is executed, all timers will no longer be executed in exit worker phase. Reference <https://github.com/nginx/nginx/blob/f02e2a734ef472f0dcf83ab2e8ce96d1acead8a5/src/os/unix/ngx_process_cycle.c#L715>.
8546+
85428547
This API was first introduced in the `v0.8.0` release.
85438548

85448549
[Back to TOC](#nginx-api-for-lua)
@@ -8548,7 +8553,7 @@ ngx.timer.every
85488553

85498554
**syntax:** *hdl, err = ngx.timer.every(delay, callback, user_arg1, user_arg2, ...)*
85508555

8551-
**context:** *init_worker_by_lua&#42;, set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, log_by_lua&#42;, ngx.timer.&#42;, balancer_by_lua&#42;, ssl_certificate_by_lua&#42;, ssl_session_fetch_by_lua&#42;, ssl_session_store_by_lua&#42;, exit_worker_by_lua&#42;*
8556+
**context:** *init_worker_by_lua&#42;, set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, log_by_lua&#42;, ngx.timer.&#42;, balancer_by_lua&#42;, ssl_certificate_by_lua&#42;, ssl_session_fetch_by_lua&#42;, ssl_session_store_by_lua&#42;*
85528557

85538558
Similar to the [ngx.timer.at](#ngxtimerat) API function, but
85548559

doc/HttpLuaModule.wiki

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7196,7 +7196,7 @@ See also [[#lua_check_client_abort|lua_check_client_abort]].
71967196
71977197
'''syntax:''' ''hdl, err = ngx.timer.at(delay, callback, user_arg1, user_arg2, ...)''
71987198
7199-
'''context:''' ''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*''
7199+
'''context:''' ''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*''
72007200
72017201
Creates an Nginx timer with a user callback function as well as optional user arguments.
72027202
@@ -7328,13 +7328,15 @@ table. It won't share the same `ngx.ctx` with the Lua handler creating the timer
73287328
If you need to pass data from the timer creator to the timer handler, please
73297329
use the extra parameters of `ngx.timer.at()`.
73307330
7331+
Since nginx has been confirmed that all timers have been cleaned up when exit worker is executed, all timers will no longer be executed in exit worker phase. Reference https://github.com/nginx/nginx/blob/f02e2a734ef472f0dcf83ab2e8ce96d1acead8a5/src/os/unix/ngx_process_cycle.c#L715.
7332+
73317333
This API was first introduced in the <code>v0.8.0</code> release.
73327334
73337335
== ngx.timer.every ==
73347336
73357337
'''syntax:''' ''hdl, err = ngx.timer.every(delay, callback, user_arg1, user_arg2, ...)''
73367338
7337-
'''context:''' ''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*''
7339+
'''context:''' ''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*''
73387340
73397341
Similar to the [[#ngx.timer.at|ngx.timer.at]] API function, but
73407342

src/ngx_http_lua_timer.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ ngx_http_lua_ngx_timer_helper(lua_State *L, int every)
174174

175175
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
176176

177+
/*
178+
* Since nginx has been confirmed that all timers have been cleaned up when
179+
* exit worker is executed, all timers will no longer be executed in exit
180+
* worker phase.
181+
* Reference https://github.com/nginx/nginx/blob/f02e2a734ef472f0dcf83ab2
182+
* e8ce96d1acead8a5/src/os/unix/ngx_process_cycle.c#L715
183+
*/
184+
ngx_http_lua_check_context(L, ctx, ~NGX_HTTP_LUA_CONTEXT_EXIT_WORKER);
185+
177186
if (ngx_exiting && delay > 0) {
178187
lua_pushnil(L);
179188
lua_pushliteral(L, "process exiting");

t/162-exit-worker.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use Test::Nginx::Socket::Lua;
55
master_on();
66
repeat_each(2);
77

8-
plan tests => repeat_each() * (blocks() * 2 + 2) + 12;
8+
plan tests => repeat_each() * (blocks() * 2 + 2) + 11;
99

1010
#log_level("warn");
1111
no_long_string();
@@ -79,7 +79,7 @@ hello, world
7979

8080

8181

82-
=== TEST 4: exit_worker_by_lua single process ngx.timer not work
82+
=== TEST 4: ngx.timer is not allow
8383
--- http_config
8484
exit_worker_by_lua_block {
8585
local function bar()
@@ -101,8 +101,8 @@ hello, world
101101
GET /t
102102
--- response_body
103103
ok
104-
--- no_error_log
105-
[error]
104+
--- shutdown_error_log
105+
API disabled in the context of exit_worker_by_lua*
106106

107107

108108

0 commit comments

Comments
 (0)