From ae76e6c2bc1e135fd953373dc8ab1a5d5ca7dff6 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Tue, 23 Jan 2024 11:22:16 -0800 Subject: [PATCH] fix(wasm): do not call attach() on re-entrancy --- changelog/unreleased/kong/wasm-attach.yml | 5 +++++ kong/runloop/wasm.lua | 25 ++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 changelog/unreleased/kong/wasm-attach.yml diff --git a/changelog/unreleased/kong/wasm-attach.yml b/changelog/unreleased/kong/wasm-attach.yml new file mode 100644 index 000000000000..99ae358d4018 --- /dev/null +++ b/changelog/unreleased/kong/wasm-attach.yml @@ -0,0 +1,5 @@ +message: > + **proxy-wasm**: Fixed "previous plan already attached" error thrown when a + filter triggers re-entrancy of the access handler. +type: bugfix +scope: Core diff --git a/kong/runloop/wasm.lua b/kong/runloop/wasm.lua index 70f36b798adc..9bb697cdda1b 100644 --- a/kong/runloop/wasm.lua +++ b/kong/runloop/wasm.lua @@ -922,17 +922,22 @@ function _M.attach(ctx) ctx.ran_wasm = true - local ok, err = proxy_wasm.attach(chain.c_plan) - if not ok then - log(CRIT, "failed attaching ", chain.label, " filter chain to request: ", err) - return kong.response.error(500) - end + local ok, err + if not ctx.wasm_attached then + ctx.wasm_attached = true - ok, err = proxy_wasm.set_host_properties_handlers(properties.get, - properties.set) - if not ok then - log(CRIT, "failed setting host property handlers: ", err) - return kong.response.error(500) + ok, err = proxy_wasm.attach(chain.c_plan) + if not ok then + log(CRIT, "failed attaching ", chain.label, " filter chain to request: ", err) + return kong.response.error(500) + end + + ok, err = proxy_wasm.set_host_properties_handlers(properties.get, + properties.set) + if not ok then + log(CRIT, "failed setting host property handlers: ", err) + return kong.response.error(500) + end end jit.off(proxy_wasm.start)