Skip to content

Retain cross-realm MessagePorts through forced GC - #856

Merged
wieslawsoltes merged 1 commit into
mainfrom
fix/service-worker-messageport-gc-825
Sep 20, 2026
Merged

wieslawsoltes merged 1 commit into
mainfrom
fix/service-worker-messageport-gc-825

Conversation

@wieslawsoltes

Copy link
Copy Markdown
Collaborator

Problem

Active-listener retention covered same-realm and dedicated Worker MessagePorts, but explicit low-memory collection did not reach ServiceWorker isolates. Iframe transfers also treated a peer in another V8 context as a locally traceable peer, allowing the receiving wrapper to be reclaimed even though it had an active listener.

Change

  • forward low-memory requests to every live ServiceWorker isolate on its serialized runtime thread
  • compact child native state and request V8 collection before the next dispatch
  • root an active MessagePort listener when its peer belongs to a different V8 context
  • add forced-GC ServiceWorker coverage for both onmessage and addEventListener
  • add a Code OSS-shaped iframe bootstrap gate that collects between listener installation and delivery
  • bound the 100-cycle ServiceWorker gate by queue, binding, heap, RSS, and elapsed-time checks

Validation

  • WEBSCENE_HYBRID_V8_RUNTIME_TEST_FILTER=messageport-iframe-gc webscene_hybrid_v8_runtime_tests
  • WEBSCENE_NATIVE_ENGINE_TEST_FILTER=service-worker-messageport-gc webscene_native_engine_tests
  • git diff --check

Closes #825

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.

Gate ServiceWorker and iframe MessagePorts across forced GC

1 participant