<?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>281662</bug_id>
          
          <creation_ts>2024-10-17 04:10:14 -0700</creation_ts>
          <short_desc>Transferring buffers to a closed MessageChannel causes memory leaks in Safari Networking</short_desc>
          <delta_ts>2025-12-17 19:51:43 -0800</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>Safari 18</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 26</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P1</priority>
          <bug_severity>Critical</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ivan Čurić">ivan.curic</reporter>
          <assigned_to name="Brady Eidson">beidson</assigned_to>
          <cc>ap</cc>
    
    <cc>bfulgham</cc>
    
    <cc>cdumez</cc>
    
    <cc>rreno</cc>
    
    <cc>slewis</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2068724</commentid>
    <comment_count>0</comment_count>
    <who name="Ivan Čurić">ivan.curic</who>
    <bug_when>2024-10-17 04:10:14 -0700</bug_when>
    <thetext>const { port1, port2 } = new MessageChannel();
port2.close();

port1.postMessage(e.data, [e.data.imageData.data.buffer]);

This approach can be used to alleviate memory pressure in V8 as it forces GC.

When used in Safari, this memory never gets GC&apos;d, and the leak happens in the &quot;Safari Networking&quot; process for some reason, and can&apos;t be reclaimed until you restart Safari.
You can&apos;t find this leak in the Web Inspector.

Repro:

Enable the option &quot;Toss transferable to empty MessageChannel&quot; and observe memory usage in Activity Monitor

https://imagedata-worker-leak.netlify.app/
https://github.com/ivancuric/memory-leak-repro</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2070327</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-10-24 04:11:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/138550781&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2164135</commentid>
    <comment_count>2</comment_count>
    <who name="Ivan Čurić">ivan.curic</who>
    <bug_when>2025-12-08 08:58:37 -0800</bug_when>
    <thetext>Why isn&apos;t this assigned to anyone yet?

I can literally crash anyone&apos;s device running Safari in seconds with the following snippet:

```
const { port1, port2 } = new MessageChannel();
port2.close();

setInterval(() =&gt; {
  const bufferBomb = new ArrayBuffer(1e8); // 100 MB
  const bomb = new Uint8Array(bufferBomb);
  port1.postMessage(bomb, [bomb.buffer]);
}, 0);

```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2164292</commentid>
    <comment_count>3</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2025-12-08 17:38:36 -0800</bug_when>
    <thetext>Pretty sure you can already do that by just allocating a lot of memory without returning to the runloop no? The JS running out of memory and causing the WebContent to crash is not uncommon. This is a bug for sure but saying you can crash anyone tab when you control the JS on the page does not make it higher priority or a security bug I think.

Note that the bug is assigned to someone in radar but they are likely focusing on higher priority bugs at the moment.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2164363</commentid>
    <comment_count>4</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2025-12-09 00:48:11 -0800</bug_when>
    <thetext>(In reply to Chris Dumez from comment #3)
&gt; Pretty sure you can already do that by just allocating a lot of memory
&gt; without returning to the runloop no? The JS running out of memory and
&gt; causing the WebContent to crash is not uncommon. This is a bug for sure but
&gt; saying you can crash anyone tab when you control the JS on the page does not
&gt; make it higher priority or a security bug I think.
&gt; 
&gt; Note that the bug is assigned to someone in radar but they are likely
&gt; focusing on higher priority bugs at the moment.

Oh, the leak happens in the networking process! I had missed this part of the report, sorry. I wrongly assumed it was leaking in &amp; crashing the WebContent process. This does make it higher priority indeed. I will see if we can this prioritized.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2164387</commentid>
    <comment_count>5</comment_count>
    <who name="Ivan Čurić">ivan.curic</who>
    <bug_when>2025-12-09 02:24:23 -0800</bug_when>
    <thetext>Thanks! Yeah, it leaks into the networking process, and IIRC it happens on iOS as well. It is also cumulative as long as the Safari process is open and persists across sleep/wake cycles.

Before MacOS 26 I could get an OS-level OOM alert once it grew to &gt;30GB of, I guess, compressed memory and the OS was still responsive enough to terminate Safari. However on 26.1 it just locks up and requires a power-button hard reset.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2166783</commentid>
    <comment_count>6</comment_count>
    <who name="Brady Eidson">beidson</who>
    <bug_when>2025-12-17 17:23:38 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/55599</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2166818</commentid>
    <comment_count>7</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-12-17 19:51:40 -0800</bug_when>
    <thetext>Committed 304642@main (ae1111af5882): &lt;https://commits.webkit.org/304642@main&gt;

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

    </bug>

</bugzilla>