Skip to content

Commit 66de2d3

Browse files
committed
fix: fix typo
1 parent 8f7abcc commit 66de2d3

File tree

5 files changed

+93
-18
lines changed

5 files changed

+93
-18
lines changed

README.markdown

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,9 +1585,9 @@ exit_worker_by_lua_block
15851585

15861586
**phase:** *exiting-worker*
15871587

1588-
Runs the specified Lua code upon every Nginx worker process's exiting when the master process is enabled.
1588+
Runs the specified Lua code upon every Nginx worker process's exit when the master process is enabled. When the master process is disabled, this hook will before run Nginx process exiting.
15891589

1590-
This hook is often used to release resources when [init_worker_by_lua*](#init_worker_by_lua_block) create resources, To prevent the worker exit abnormal.
1590+
This hook is ogten used to release resources allocated by each worker (e.g. resources allocated by [init_worker_by_lua*](#init_worker_by_lua)), or to prevent workers from exiting abnormally.
15911591

15921592
For example,
15931593

@@ -1603,7 +1603,7 @@ For example,
16031603
exit_worker_by_lua_file
16041604
-----------------------
16051605

1606-
**syntax:** *exit_worker_by_lua_file { lua--file-path }*
1606+
**syntax:** *exit_worker_by_lua_file { lua-file-path }*
16071607

16081608
**context:** *http*
16091609

@@ -7832,6 +7832,8 @@ Retrieves the current running phase name. Possible return values are
78327832
for the context of [log_by_lua*](#log_by_lua).
78337833
* `timer`
78347834
for the context of user callback functions for [ngx.timer.*](#ngxtimerat).
7835+
* `exit_worker`
7836+
for the context of [exit_worker_by_lua*](#exit_worker_by_lua).
78357837

78367838
This API was first introduced in the `v0.5.10` release.
78377839

doc/HttpLuaModule.wiki

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,9 @@ This hook no longer runs in the cache manager and cache loader processes since t
12851285
12861286
'''phase:''' ''exiting-worker''
12871287
1288-
Runs the specified Lua code upon every Nginx worker process's exiting when the master process is enabled. When the master process is disabled, this hook will before run Nginx process exiting.
1288+
Runs the specified Lua code upon every Nginx worker process's exit when the master process is enabled. When the master process is disabled, this hook will before run Nginx process exiting.
12891289
1290-
This hook is often used to release resources when [[#init_worker_by_lua|init_worker_by_lua*]] create resources, to prevent the worker from exiting abnormally.
1290+
This hook is ogten used to release resources allocated by each worker (e.g. resources allocated by [[#init_worker_by_lua|init_worker_by_lua*]]), or to prevent workers from exiting abnormally.
12911291
12921292
For example,
12931293
@@ -1299,7 +1299,7 @@ For example,
12991299
13001300
== exit_worker_by_lua_file ==
13011301
1302-
'''syntax:''' ''exit_worker_by_lua_file { lua--file-path }''
1302+
'''syntax:''' ''exit_worker_by_lua_file { lua-file-path }''
13031303
13041304
'''context:''' ''http''
13051305
@@ -6660,6 +6660,8 @@ Retrieves the current running phase name. Possible return values are
66606660
: for the context of [[#log_by_lua|log_by_lua*]].
66616661
* <code>timer</code>
66626662
: for the context of user callback functions for [[#ngx.timer.at|ngx.timer.*]].
6663+
* <code>exit_worker</code>
6664+
: for the context of [[#exit_worker_by_lua|exit_worker_by_lua*]].
66636665
66646666
This API was first introduced in the <code>v0.5.10</code> release.
66656667

src/ngx_http_lua_exitworkerby.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ ngx_http_lua_exit_worker(ngx_cycle_t *cycle)
2626
lmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_lua_module);
2727
if (lmcf == NULL
2828
|| lmcf->exit_worker_handler == NULL
29-
|| lmcf->lua == NULL)
29+
|| lmcf->lua == NULL
30+
#if !(NGX_WIN32)
31+
|| (ngx_process == NGX_PROCESS_HELPER
32+
# ifdef HAVE_PRIVILEGED_PROCESS_PATCH
33+
&& !ngx_is_privileged_agent
34+
# endif
35+
)
36+
#endif /* NGX_WIN32 */
37+
)
3038
{
3139
return;
3240
}
@@ -89,13 +97,13 @@ ngx_http_lua_exit_worker_by_inline(ngx_log_t *log,
8997

9098

9199
ngx_int_t
92-
ngx_http_lua_exit_worker_by_file(ngx_log_t *log,
93-
ngx_http_lua_main_conf_t *lmcf, lua_State *L)
100+
ngx_http_lua_exit_worker_by_file(ngx_log_t *log, ngx_http_lua_main_conf_t *lmcf,
101+
lua_State *L)
94102
{
95103
int status;
96104

97105
status = luaL_loadfile(L, (char *) lmcf->exit_worker_src.data)
98106
|| ngx_http_lua_do_call(log, L);
99107

100-
return ngx_http_lua_report(log, L, status, "exit_worker_by_file");
108+
return ngx_http_lua_report(log, L, status, "exit_worker_by_lua_file");
101109
}

t/089-phase.t

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ log_level('warn');
88

99
repeat_each(2);
1010

11-
plan tests => repeat_each() * (blocks() * 2) + 3;
11+
plan tests => repeat_each() * (blocks() * 2 + 2);
1212

1313
#no_diff();
1414
#no_long_string();
@@ -184,6 +184,7 @@ init_worker
184184
exit_worker_by_lua_block {
185185
local phase = ngx.get_phase()
186186
ngx.log(ngx.ERR, phase)
187+
ngx.log(ngx.ERR, "exiting now")
187188
}
188189
--- config
189190
location /lua {
@@ -195,5 +196,8 @@ init_worker
195196
GET /lua
196197
--- response_body
197198
ok
198-
--- shutdown_error_log
199-
exit_worker_by_lua:3: exit_worker
199+
--- shutdown_error_log eval
200+
[
201+
qr/exit_worker_by_lua:\d+: exit_worker/,
202+
qr/exiting now$/,
203+
]

t/162-exit-worker.t

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
use Test::Nginx::Socket::Lua;
44

5+
master_on();
56
repeat_each(2);
67

7-
plan tests => repeat_each() * (blocks() * 2 + 2);
8+
plan tests => repeat_each() * (blocks() * 2 + 7);
89

910
#log_level("warn");
1011
no_long_string();
@@ -87,7 +88,7 @@ hello, world
8788

8889
local ok, err = ngx.timer.at(0, bar)
8990
if not ok then
90-
ngx.log(ngx.ERR, "failed to create timer: " .. err)
91+
ngx.log(ngx.ERR, "failed to create timer: ", err)
9192
else
9293
ngx.log(ngx.NOTICE, "success")
9394
end
@@ -101,19 +102,20 @@ GET /t
101102
--- response_body
102103
ok
103104
--- no_error_log
105+
[error]
104106

105107

106108

107109
=== TEST 5: exit_worker_by_lua use shdict
108110
--- http_config
109-
lua_shared_dict dog 10m;
111+
lua_shared_dict dog 1m;
110112
exit_worker_by_lua_block {
111113
local dog = ngx.shared.dog
112114
local val, err = dog:get("foo")
113115
if not val then
114-
ngx.log(ngx.ERR, "failed get shdict: " .. err)
116+
ngx.log(ngx.ERR, "failed get shdict: ", err)
115117
else
116-
ngx.log(ngx.NOTICE, "get val: " .. val)
118+
ngx.log(ngx.NOTICE, "get val: ", val)
117119
end
118120
}
119121
--- config
@@ -130,3 +132,60 @@ GET /t
130132
ok
131133
--- shutdown_error_log
132134
get val: 100
135+
136+
137+
138+
=== TEST 6: skip in cache processes (with exit worker and privileged agent)
139+
--- http_config
140+
lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
141+
142+
proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:1m;
143+
144+
init_by_lua_block {
145+
assert(require "ngx.process".enable_privileged_agent())
146+
}
147+
148+
exit_worker_by_lua_block {
149+
ngx.log(ngx.NOTICE, "hello from exit worker by lua")
150+
}
151+
--- config
152+
location = /t {
153+
return 200;
154+
}
155+
--- request
156+
GET /t
157+
--- no_error_log
158+
[error]
159+
--- shutdown_error_log eval
160+
[
161+
qr/cache loader process \d+ exited/,
162+
qr/cache manager process \d+ exited/,
163+
qr/hello from exit worker by lua$/,
164+
qr/hello from exit worker by lua$/,
165+
qr/privileged agent process \d+ exited/,
166+
]
167+
168+
169+
170+
=== TEST 7: skipin cache processes (with init worker but without privileged agent)
171+
--- http_config
172+
lua_package_path "../lua-resty-core/lib/?.lua;../lua-resty-lrucache/lib/?.lua;;";
173+
174+
proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:1m;
175+
176+
exit_worker_by_lua_block {
177+
ngx.log(ngx.WARN, "hello from exit worker by lua")
178+
}
179+
--- config
180+
location = /t {
181+
return 200;
182+
}
183+
--- request
184+
GET /t
185+
--- no_error_log
186+
[error]
187+
start privileged agent process
188+
--- shutdown_error_log eval
189+
[
190+
qr/hello from exit worker by lua$/,
191+
]

0 commit comments

Comments
 (0)