fix: make WasmBase::doAfterVmCallActions reentry-safe (drain-to-local) - #12
Merged
Merged
Conversation
Signed-off-by: 澄潭 <zty98751@alibaba-inc.com>
Signed-off-by: 澄潭 <zty98751@alibaba-inc.com>
johnlanni
force-pushed
the
fix/doaftervmcallactions-drain-to-local
branch
from
July 6, 2026 06:24
304bf0d to
8373227
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
WasmBase::doAfterVmCallActions()drained itsafter_vm_call_actions_queue with anunguarded
while (!after_vm_call_actions_.empty())loop, popping and running one actionat 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
injectEncodedDataToFilterChainfrom within an after-VM-call action, which schedulesanother 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::dequebefore draining, then iterate the localsnapshot 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
DeferAfterCallActionsframe instead of being re-run in this loop. This breaks thesynchronous-reentry spin while preserving ordering semantics for legitimately deferred work.
This is a header-only change to a small inline method:
Test
Adds
TEST_P(TestVm, DoAfterVmCallActionsReentrySafe)intest/wasm_test.cc, wired into theexisting
//test:wasm_testtarget. It registers a self-re-enqueuing action and asserts thecount advances by exactly one per
doAfterVmCallActions()call. On the old code this testwould hang forever (documenting the regression); with the fix each drain runs the snapshot
once and defers the re-added copy.
Notes
Refs
WasmBase::doAfterVmCallActions(Layer A, #4034) higress#4070 (Layer A)