Skip to content

Keep active Worker MessagePorts reachable - #436

Merged
wieslawsoltes merged 1 commit into
mainfrom
agent/issue-288-worker-lifetime
Sep 18, 2026
Merged

wieslawsoltes merged 1 commit into
mainfrom
agent/issue-288-worker-lifetime

Conversation

@wieslawsoltes

Copy link
Copy Markdown
Collaborator

An active transferred MessagePort in a dedicated Worker could lose its wrapper during GC because local peer edges end at the isolate boundary. A Worker that installed onmessage or an EventTarget listener could therefore stop receiving future messages after the parent requested low-memory collection.

This change roots only started, remotely entangled ports with active message/messageerror listeners. It releases that root on handler/listener removal, abort/once dispatch, transfer, explicit or collected peer close, Worker termination, navigation, and runtime teardown. Parent low-memory notification now synchronously requests collection on live Worker isolate threads, which makes the cross-isolate regression deterministic.

Validation:

  • Chrome 153 contract: 1/1 document, 3/3 subtests; 100 transfer/release cycles in 124 ms
  • native contract: 1/1 document, 3/3 subtests; final exact-head run in 852 ms
  • native forced-GC lifecycle: 100 cycles in 1.03 s; 2 binding slots, 0 retained bindings, 0 queued messages/bytes; heap 879,384 -> 662,368 bytes; RSS 38.0 -> 41.2 MB
  • existing 1,000-cycle same-realm forced-GC stress: p95 2.81 ms, max 11.79 ms; 0 retained/queued; bounded heap/RSS
  • existing 10,000-message Worker throughput and complete Worker/MessagePort aggregate pass

Advances #288. Related to #81 and #227.

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