<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>313389</bug_id>
          
          <creation_ts>2026-04-26 22:58:25 -0700</creation_ts>
          <short_desc>WorkerMessagingProxy objects leak after calling worker.terminate() from JavaScript</short_desc>
          <delta_ts>2026-04-28 19:52:16 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>22723</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="David Kilzer (:ddkilzer)">ddkilzer</reporter>
          <assigned_to name="David Kilzer (:ddkilzer)">ddkilzer</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2204759</commentid>
    <comment_count>0</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2026-04-26 22:58:25 -0700</bug_when>
    <thetext>`WorkerMessagingProxy` objects leak after calling `worker.terminate()` from JavaScript.

The proxy ref-counting has a two-phase cleanup: `terminateWorkerGlobalScope()` shuts down the worker thread (phase 1), then `workerObjectDestroyed()` releases the initial ref when the `Worker` DOM object is destroyed (phase 2). The bug is that phase 1 clears `m_scriptExecutionContextIdentifier`, which phase 2 needs to post its cleanup task. Specifically, `workerGlobalScopeDestroyedInternal()` runs with `m_mayBeDestroyed == false` (set only by `workerObjectDestroyed()`), so it skips `deref()` and sets `m_scriptExecutionContextIdentifier = std::nullopt`. When `Worker::~Worker()` later calls `workerObjectDestroyed()`, the nullopt identifier causes an early return, and `deref()` is never called.

A secondary retain cycle exists when messages are queued in `m_queuedEarlyTasks` before the worker thread is created. The queued task lambdas capture `Ref { *this }`, creating a cycle through the proxy&apos;s own member vector that prevents destruction even if `deref()` were called.

Observed as ROOT LEAK (957 instances of `WorkerMessagingProxy`) and ROOT CYCLE (88 retain cycles with `WorkerMessagingProxy` and `CallableWrapper`) across 20 of 103 WebContent process memgraphs from a full `run-webkit-tests --leaks --debug` run.

Tests that exercise the bug include:
- workers/worker-terminate-crash.html
- workers/bomb.html
- workers/worker-set-delete-terminate-crash.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2204760</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2026-04-26 22:58:33 -0700</bug_when>
    <thetext>&lt;rdar://problem/175652847&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2204775</commentid>
    <comment_count>2</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2026-04-26 23:34:03 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/63665</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2205628</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-04-28 19:52:14 -0700</bug_when>
    <thetext>Committed 312256@main (80cc99fb32cb): &lt;https://commits.webkit.org/312256@main&gt;

Reviewed commits have been landed. Closing PR #63665 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>