Skip to content

Commit 263bd0c

Browse files
bugfix: should not allow to create timer in the exit process phase (#1907)
Since the exit process phase runs after all timers have been processed.
1 parent b721656 commit 263bd0c

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
@@ -1672,6 +1672,8 @@ For example,
16721672
}
16731673
```
16741674

1675+
It's not allowed to create a timer (even a 0-delay timer) here since it runs after all timers have been processed.
1676+
16751677
This directive was first introduced in the `v0.10.18` release.
16761678

16771679
[Back to TOC](#directives)
@@ -3154,9 +3156,10 @@ The directive is supported when using OpenSSL 1.0.2 or higher and nginx 1.19.4 o
31543156

31553157
Several `lua_ssl_conf_command` directives can be specified on the same level:
31563158

3157-
```
3158-
lua_ssl_conf_command Options PrioritizeChaCha;
3159-
lua_ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;
3159+
```nginx
3160+
3161+
lua_ssl_conf_command Options PrioritizeChaCha;
3162+
lua_ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;
31603163
```
31613164

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

31663169
This directive was first introduced in the `v0.10.21` release.
31673170

3171+
3172+
31683173
[Back to TOC](#directives)
31693174

31703175
lua_http10_buffering
@@ -8405,7 +8410,7 @@ ngx.timer.at
84058410

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

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**
8413+
**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**
84098414

84108415
Creates an Nginx timer with a user callback function as well as optional user arguments.
84118416

@@ -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*, 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**
8556+
**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**
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
@@ -1362,6 +1362,8 @@ For example,
13621362
}
13631363
</geshi>
13641364
1365+
It's not allowed to create a timer (even a 0-delay timer) here since it runs after all timers have been processed.
1366+
13651367
This directive was first introduced in the <code>v0.10.18</code> release.
13661368
13671369
== exit_worker_by_lua_file ==
@@ -7196,7 +7198,7 @@ See also [[#lua_check_client_abort|lua_check_client_abort]].
71967198
71977199
'''syntax:''' ''hdl, err = ngx.timer.at(delay, callback, user_arg1, user_arg2, ...)''
71987200
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*''
7201+
'''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*''
72007202
72017203
Creates an Nginx timer with a user callback function as well as optional user arguments.
72027204
@@ -7334,7 +7336,7 @@ This API was first introduced in the <code>v0.8.0</code> release.
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)