diff --git a/src/common/lua/ngx_wasm_lua_ffi.c b/src/common/lua/ngx_wasm_lua_ffi.c index 070fc6206..a58b18cc4 100644 --- a/src/common/lua/ngx_wasm_lua_ffi.c +++ b/src/common/lua/ngx_wasm_lua_ffi.c @@ -184,14 +184,22 @@ ngx_int_t ngx_http_wasm_ffi_set_property(ngx_http_request_t *r, ngx_str_t *key, ngx_str_t *value) { - ngx_http_wasm_req_ctx_t *rctx; - ngx_proxy_wasm_ctx_t *pwctx; + ngx_http_wasm_req_ctx_t *rctx; + ngx_proxy_wasm_ctx_t *pwctx; + ngx_proxy_wasm_subsystem_t *subsystem = NULL; + +#ifdef NGX_WASM_HTTP + subsystem = &ngx_http_proxy_wasm; +#endif if (ngx_http_wasm_rctx(r, &rctx) != NGX_OK) { return NGX_ERROR; } - pwctx = ngx_http_proxy_wasm.get_context(rctx); + pwctx = ngx_proxy_wasm_ctx(NULL, 0, + NGX_PROXY_WASM_ISOLATION_STREAM, + subsystem, + rctx); if (pwctx == NULL) { return NGX_ERROR; } @@ -204,8 +212,13 @@ ngx_int_t ngx_http_wasm_ffi_get_property(ngx_http_request_t *r, ngx_str_t *key, ngx_str_t *value) { - ngx_http_wasm_req_ctx_t *rctx; - ngx_proxy_wasm_ctx_t *pwctx; + ngx_http_wasm_req_ctx_t *rctx; + ngx_proxy_wasm_ctx_t *pwctx; + ngx_proxy_wasm_subsystem_t *subsystem = NULL; + +#ifdef NGX_WASM_HTTP + subsystem = &ngx_http_proxy_wasm; +#endif if (ngx_http_wasm_rctx(r, &rctx) != NGX_OK) { /* @@ -215,7 +228,10 @@ ngx_http_wasm_ffi_get_property(ngx_http_request_t *r, return NGX_ERROR; } - pwctx = ngx_http_proxy_wasm.get_context(rctx); + pwctx = ngx_proxy_wasm_ctx(NULL, 0, + NGX_PROXY_WASM_ISOLATION_STREAM, + subsystem, + rctx); if (pwctx == NULL) { return NGX_ERROR; } diff --git a/src/http/proxy_wasm/ngx_http_proxy_wasm.c b/src/http/proxy_wasm/ngx_http_proxy_wasm.c index c38d56622..af7943f58 100644 --- a/src/http/proxy_wasm/ngx_http_proxy_wasm.c +++ b/src/http/proxy_wasm/ngx_http_proxy_wasm.c @@ -346,6 +346,15 @@ ngx_http_proxy_wasm_ecode(ngx_proxy_wasm_err_e ecode) } +static void +ngx_http_wasm_ffi_cleanup_handler(void *data) +{ + ngx_proxy_wasm_ctx_t *pwctx = data; + + ngx_proxy_wasm_ctx_destroy(pwctx); +} + + static ngx_proxy_wasm_ctx_t * ngx_http_proxy_wasm_ctx(void *data) { @@ -353,6 +362,7 @@ ngx_http_proxy_wasm_ctx(void *data) ngx_http_wasm_req_ctx_t *rctx = data; ngx_http_request_t *r = rctx->r; ngx_http_wasm_loc_conf_t *loc; + ngx_pool_cleanup_t *cln; loc = ngx_http_get_module_loc_conf(r, ngx_http_wasm_module); @@ -374,6 +384,16 @@ ngx_http_proxy_wasm_ctx(void *data) /* for on_request_body retrieval */ rctx->data = pwctx; + + if (rctx->fake_request) { + cln = ngx_pool_cleanup_add(pwctx->parent_pool, 0); + if (cln == NULL) { + return NULL; + } + + cln->handler = ngx_http_wasm_ffi_cleanup_handler; + cln->data = pwctx; + } } return pwctx;