Skip to content

Keep runtime schedulers safe through teardown - #254

Open
matthargett wants to merge 1 commit into
BabylonJS:mainfrom
rebeckerspecialties:fix/runtime-scheduler-lifetime
Open

matthargett wants to merge 1 commit into
BabylonJS:mainfrom
rebeckerspecialties:fix/runtime-scheduler-lifetime

Conversation

@matthargett

@matthargett matthargett commented Sep 17, 2026

Copy link
Copy Markdown

Summary

  • Share synchronized dispatch state so scheduler copies safely outlive their runtime.
  • Close dispatch before AppRuntime discards pending work; retain finalizer cleanup and release dispatch captures outside the lock.
  • Accept mutable and Napi::Env callbacks while preserving existing const/zero-argument overload behavior. Add ten bounded native tests with owned timeout state.

Validation

macOS 27.0 arm64, SDK 27.0, LLVM 23.1.1, real system JavaScriptCore. A native-only target compiled the committed scheduler test file and runtime, reusing dependency sources read-only:

  • JSC_collectContinuously=1 SchedulerTests --gtest_repeat=20: 200/200 passed.
  • Same run with ENABLE_THREAD_SANITIZER=ON, TSAN_OPTIONS=halt_on_error=1: 200/200 passed, no TSan reports. System JSC itself is not instrumented.
  • A bounded ASan/UBSan subprocess against pristine upstream 839b352 reproduced post-destruction dispatch failure: mutex lock failed: Invalid argument. No ASan UAF diagnostic was emitted.
  • git diff --check passed. No npm/polyfill suite or other engines were tested.

Provenance

Adapted from Matt Hargett's integration commits 7093c83d3a29020fc52f070859b7f7514ed3195f and 0a5d570d156d75f5fc01162f5fe6a7ccc891e3c3. This standalone commit preserves the original author/date and adds explicit host shutdown ordering, unlocked capture release, callable compatibility, and bounded tests on upstream main.

Note: this latent issue was discovered by the ChatGPT DayBreak model when I was doing adversarial testing on my webgpu branch.

Share synchronized dispatch state with scheduler copies, close it before AppRuntime discards pending work, and release dispatch captures outside the lock. Preserve existing callable overload behavior while accepting mutable and environment-taking callbacks. Add bounded native regression tests with owned timeout state.

Adapted from integration commits by Matt Hargett:

Source-commit: 7093c83
Source-commit: 0a5d570
Copilot AI lite review requested due to automatic review settings September 17, 2026 22:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@matthargett

Copy link
Copy Markdown
Author

Also validated this change in the integrated browser-polyfill stack on M4 Max/system JavaScriptCore with JSC_collectContinuously=1: all 55 native tests passed, including 362 JavaScript cases and the worker WPT subset (three existing JavaScript skips). The standalone TSan results remain recorded above.

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.

2 participants