Skip to content

Commit

Permalink
fix(wasm): do not call attach() on re-entrancy (#12402)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4d03ca4)
  • Loading branch information
flrgh committed Jan 29, 2024
1 parent c8930f4 commit 9c30a7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 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
19 changes: 12 additions & 7 deletions kong/runloop/wasm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,19 @@ 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.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

set_proxy_wasm_property("kong.route_id", ctx.route and ctx.route.id)
set_proxy_wasm_property("kong.service_id", ctx.service and ctx.service.id)
set_proxy_wasm_property("kong.route_id", ctx.route and ctx.route.id)
set_proxy_wasm_property("kong.service_id", ctx.service and ctx.service.id)
end

ok, err = proxy_wasm.start()
if not ok then
Expand Down

0 comments on commit 9c30a7e

Please sign in to comment.