fix(runtime): cancel WASM watchdog on early exit - #1278
Open
andyst-dev wants to merge 1 commit into
Open
Conversation
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.
Fixes #1241
Summary
sandbox.rsspawns a detached OS thread per WASM execution as an epoch watchdog: it sleeps the fulltimeout_secsand then bumps the shared engine epoch. When execution finishes early (success, fuel exhaustion, or error), the thread keeps sleeping and eventually callsincrement_epoch()on the shared engine — which can interrupt a different execution still running on the same engine.Beyond the reported thread accumulation under load, this is a cross-execution correctness bug: a stale watchdog can cut a concurrent execution short with a false "timed out" error.
Changes
WatchdogCancel) sets the flag on drop, so cancellation is guaranteed on every exit path ofexecute_sync— success, fuel exhaustion, epoch interrupt, or any error.The stale-watchdog behavior is directly observable: before the fix the test fails with
long execution was interrupted after 1.05s; after the fix it completes at its own 4s timeout.Testing
cargo test -p openfang-runtime— all tests pass (sandbox suite: 89 passed)cargo fmt -p openfang-runtime -- --check— cleancargo clippy -p openfang-runtime --lib -- -D warnings— no warnings on the changed crateSecurity