Skip to content

Commit

Permalink
fix(wasm): do not call attach() on re-entrancy
Browse files Browse the repository at this point in the history
  • Loading branch information
flrgh committed Jan 29, 2024
1 parent cb1a3c1 commit ae76e6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/kong/wasm-attach.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 15 additions & 10 deletions kong/runloop/wasm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ae76e6c

Please sign in to comment.