Skip to content

fix: make WasmBase::doAfterVmCallActions reentry-safe (drain-to-local) - #12

Merged
johnlanni merged 2 commits into
masterfrom
fix/doaftervmcallactions-drain-to-local
Jul 6, 2026
Merged

fix: make WasmBase::doAfterVmCallActions reentry-safe (drain-to-local)#12
johnlanni merged 2 commits into
masterfrom
fix/doaftervmcallactions-drain-to-local

Conversation

@johnlanni

Copy link
Copy Markdown

Problem

WasmBase::doAfterVmCallActions() drained its after_vm_call_actions_ queue with an
unguarded while (!after_vm_call_actions_.empty()) loop, popping and running one action
at a time. If an action re-enqueues itself (or otherwise adds a new action) during the
drain, the freshly-added action is observed by the same loop and executed again in the
same frame. Under synchronous reentry — e.g. a plugin that calls
injectEncodedDataToFilterChain from within an after-VM-call action, which schedules
another after-VM-call action — the loop never sees an empty queue and spins forever,
pinning a CPU at 100%.

Fix

Swap the member queue into a local std::deque before draining, then iterate the local
snapshot exactly once. Actions re-added by a callback during the drain land in the
(now-empty) member queue and are therefore picked up by the next-outer
DeferAfterCallActions frame instead of being re-run in this loop. This breaks the
synchronous-reentry spin while preserving ordering semantics for legitimately deferred work.

This is a header-only change to a small inline method:

  • Zero-ABI / transparent to plugins — no signature or behavior change visible to WASM modules.
  • Re-added actions are still executed; they are just deferred to the next-outer frame.

Test

Adds TEST_P(TestVm, DoAfterVmCallActionsReentrySafe) in test/wasm_test.cc, wired into the
existing //test:wasm_test target. It registers a self-re-enqueuing action and asserts the
count advances by exactly one per doAfterVmCallActions() call. On the old code this test
would hang forever (documenting the regression); with the fix each drain runs the snapshot
once and defers the re-added copy.

Notes

  • CI is the build/test gate.
  • Merge is intentionally gated on maintainer review — please do not self-merge.

Refs

johnlanni added 2 commits July 6, 2026 14:24
Signed-off-by: 澄潭 <zty98751@alibaba-inc.com>
Signed-off-by: 澄潭 <zty98751@alibaba-inc.com>
@johnlanni
johnlanni force-pushed the fix/doaftervmcallactions-drain-to-local branch from 304bf0d to 8373227 Compare July 6, 2026 06:24
@johnlanni
johnlanni merged commit d1ab18f into master Jul 6, 2026
3 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant