Skip to content

Commit

Permalink
fix(*) ensure fake requests filter chains are freed
Browse files Browse the repository at this point in the history
Such as fake request passed to the FFI via the init_worker_by_lua fake
request.
  • Loading branch information
thibaultcha committed Sep 27, 2023
1 parent d3a22dc commit e0f5a9f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/common/lua/ngx_wasm_lua_ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ ngx_http_wasm_ffi_set_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,
&ngx_http_proxy_wasm, rctx);
if (pwctx == NULL) {
return NGX_ERROR;
}
Expand All @@ -208,14 +210,16 @@ ngx_http_wasm_ffi_get_property(ngx_http_request_t *r,
ngx_proxy_wasm_ctx_t *pwctx;

if (ngx_http_wasm_rctx(r, &rctx) != NGX_OK) {
/*
/**
* TODO: return code signifying "no plan attached to request" and co.
* return associated constant as err/code from Lua lib
*/
return NGX_ERROR;
}

pwctx = ngx_http_proxy_wasm.get_context(rctx);
pwctx = ngx_proxy_wasm_ctx(NULL, 0,
NGX_PROXY_WASM_ISOLATION_STREAM,
&ngx_http_proxy_wasm, rctx);
if (pwctx == NULL) {
return NGX_ERROR;
}
Expand Down
20 changes: 20 additions & 0 deletions src/http/proxy_wasm/ngx_http_proxy_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,23 @@ ngx_http_proxy_wasm_ecode(ngx_proxy_wasm_err_e ecode)
}


static void
ngx_http_proxy_wasm_ctx_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)
{
ngx_proxy_wasm_ctx_t *pwctx;
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);

Expand All @@ -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_proxy_wasm_ctx_cleanup_handler;
cln->data = pwctx;
}
}

return pwctx;
Expand Down

0 comments on commit e0f5a9f

Please sign in to comment.