Skip to content

Commit fa0cd87

Browse files
committed
fix(proxy-wasm) support get 'plugin_name' in tick context
No filter chain initialized on tick contexts means the root context must be stored in the empty filter chain context for later retrieval.
1 parent 6138510 commit fa0cd87

File tree

4 files changed

+60
-8
lines changed

4 files changed

+60
-8
lines changed

src/common/proxy_wasm/ngx_proxy_wasm.c

+3
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,12 @@ ngx_proxy_wasm_run_step(ngx_proxy_wasm_exec_t *pwexec,
840840
rc = filter->subsystem->resume(pwexec, step, &action);
841841
break;
842842
case NGX_PROXY_WASM_STEP_TICK:
843+
ngx_wa_assert(pwexec->root_id == NGX_PROXY_WASM_ROOT_CTX_ID);
844+
pwctx->rexec = pwexec;
843845
pwexec->in_tick = 1;
844846
rc = ngx_proxy_wasm_on_tick(pwexec);
845847
pwexec->in_tick = 0;
848+
pwctx->rexec = NULL;
846849
break;
847850
default:
848851
ngx_proxy_wasm_log_error(NGX_LOG_WASM_NYI, pwctx->log, 0,

src/common/proxy_wasm/ngx_proxy_wasm.h

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ struct ngx_proxy_wasm_ctx_s {
213213
ngx_uint_t isolation;
214214
ngx_proxy_wasm_store_t store;
215215
ngx_proxy_wasm_context_type_e type;
216+
ngx_proxy_wasm_exec_t *rexec; /* root exec ctx */
216217
ngx_log_t *log;
217218
ngx_pool_t *pool;
218219
ngx_pool_t *parent_pool;

src/common/proxy_wasm/ngx_proxy_wasm_properties.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,15 @@ get_filter_name(ngx_proxy_wasm_ctx_t *pwctx, ngx_str_t *path,
378378
ngx_proxy_wasm_exec_t *pwexec, *pwexecs;
379379
ngx_proxy_wasm_filter_t *filter;
380380

381-
pwexecs = (ngx_proxy_wasm_exec_t *) pwctx->pwexecs.elts;
382-
pwexec = &pwexecs[pwctx->exec_index];
383-
filter = pwexec->filter;
381+
if (pwctx->step == NGX_PROXY_WASM_STEP_TICK) {
382+
/* no filter chain initialized */
383+
filter = pwctx->rexec->filter;
384+
385+
} else {
386+
pwexecs = (ngx_proxy_wasm_exec_t *) pwctx->pwexecs.elts;
387+
pwexec = &pwexecs[pwctx->exec_index];
388+
filter = pwexec->filter;
389+
}
384390

385391
value->len = filter->name->len;
386392
value->data = filter->name->data;

t/03-proxy_wasm/hfuncs/117-proxy_properties_get.t

+47-5
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,49 @@ qr/request\.is_subrequest: true at RequestHeaders/
695695
696696
697697
698-
=== TEST 16: proxy_wasm - get_property() - unknown property on: request_headers
698+
=== TEST 16: proxy_wasm - get_property() plugin_name on: tick
699+
--- wasm_modules: hostcalls
700+
--- load_nginx_modules: ngx_http_echo_module
701+
--- config
702+
location /t {
703+
proxy_wasm hostcalls 'tick_period=200 \
704+
on_tick=log_property \
705+
name=plugin_name';
706+
echo_sleep 0.5;
707+
echo ok;
708+
}
709+
--- response_body
710+
ok
711+
--- error_log
712+
plugin_name: hostcalls
713+
--- no_error_log
714+
[error]
715+
[crit]
716+
717+
718+
719+
=== TEST 17: proxy_wasm - get_property() plugin_root_id on: tick
720+
--- wasm_modules: hostcalls
721+
--- load_nginx_modules: ngx_http_echo_module
722+
--- config
723+
location /t {
724+
proxy_wasm hostcalls 'tick_period=200 \
725+
on_tick=log_property \
726+
name=plugin_root_id';
727+
echo_sleep 0.5;
728+
echo ok;
729+
}
730+
--- response_body
731+
ok
732+
--- error_log
733+
plugin_root_id: 0
734+
--- no_error_log
735+
[error]
736+
[crit]
737+
738+
739+
740+
=== TEST 18: proxy_wasm - get_property() - unknown property on: request_headers
699741
--- wasm_modules: hostcalls
700742
--- load_nginx_modules: ngx_http_echo_module
701743
--- config
@@ -714,7 +756,7 @@ qr/\[info\] .*? property not found: nonexistent_property,/
714756
715757
716758
717-
=== TEST 17: proxy_wasm - get_property() request.* - not available on: tick (isolation: global)
759+
=== TEST 19: proxy_wasm - get_property() request.* - not available on: tick (isolation: global)
718760
--- skip_hup
719761
--- wasm_modules: hostcalls
720762
--- load_nginx_modules: ngx_http_echo_module
@@ -737,7 +779,7 @@ qr/\[info\] .*? property not found: nonexistent_property,/
737779
738780
739781
740-
=== TEST 18: proxy_wasm - get_property() response.* - not available on: tick (isolation: global)
782+
=== TEST 20: proxy_wasm - get_property() response.* - not available on: tick (isolation: global)
741783
--- skip_hup
742784
--- wasm_modules: hostcalls
743785
--- load_nginx_modules: ngx_http_echo_module
@@ -760,7 +802,7 @@ qr/\[info\] .*? property not found: nonexistent_property,/
760802
761803
762804
763-
=== TEST 19: proxy_wasm - get_property() upstream.* - not available on: tick (isolation: global)
805+
=== TEST 21: proxy_wasm - get_property() upstream.* - not available on: tick (isolation: global)
764806
--- skip_hup
765807
--- wasm_modules: hostcalls
766808
--- load_nginx_modules: ngx_http_echo_module
@@ -783,7 +825,7 @@ qr/\[info\] .*? property not found: nonexistent_property,/
783825
784826
785827
786-
=== TEST 20: proxy_wasm - get_property() upstream.* - not available on: configure (isolation: global)
828+
=== TEST 22: proxy_wasm - get_property() upstream.* - not available on: configure (isolation: global)
787829
--- skip_hup
788830
--- wasm_modules: hostcalls
789831
--- load_nginx_modules: ngx_http_echo_module

0 commit comments

Comments
 (0)