Title: [291127] trunk/Source/WebCore
Revision
291127
Author
[email protected]
Date
2022-03-10 13:27:29 -0800 (Thu, 10 Mar 2022)

Log Message

Document is leaking on haaretz.co.il due to an async script
https://bugs.webkit.org/show_bug.cgi?id=237672
<rdar://problem/90050632>

Reviewed by Geoffrey Garen.

I haven't been able to reproduce this in the context of a layout test, however,
I see the https://acdn.adnxs.com/dmp/async_usersync.html document flakily leaking
on haaretz.co.il due to an async script (sometimes the top document too).

>From a memgraph, I can see that the cycle is:
HTMLDocument -> ScriptRunner -> PendingScript (via m_scriptsToExecuteSoon) -> HTMLScriptElement -> HTMLDocument (again)

To address the issue, I updated Document::commonTeardown() to clear all its ScriptRunner's pending scripts, right after
we stop all ActiveDOMObjects. At this point, we no longer want to run script and clearing any pending scripts is critical
since they hold a strong reference to the Document.

I have validated the fix on haaretz.co.il since I wasn't able to write an automated
test for this.

* dom/Document.cpp:
(WebCore::Document::commonTeardown):
* dom/ScriptRunner.cpp:
(WebCore::ScriptRunner::clearPendingScripts):
* dom/ScriptRunner.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (291126 => 291127)


--- trunk/Source/WebCore/ChangeLog	2022-03-10 21:25:37 UTC (rev 291126)
+++ trunk/Source/WebCore/ChangeLog	2022-03-10 21:27:29 UTC (rev 291127)
@@ -1,3 +1,31 @@
+2022-03-10  Chris Dumez  <[email protected]>
+
+        Document is leaking on haaretz.co.il due to an async script
+        https://bugs.webkit.org/show_bug.cgi?id=237672
+        <rdar://problem/90050632>
+
+        Reviewed by Geoffrey Garen.
+
+        I haven't been able to reproduce this in the context of a layout test, however,
+        I see the https://acdn.adnxs.com/dmp/async_usersync.html document flakily leaking
+        on haaretz.co.il due to an async script (sometimes the top document too).
+
+        From a memgraph, I can see that the cycle is:
+        HTMLDocument -> ScriptRunner -> PendingScript (via m_scriptsToExecuteSoon) -> HTMLScriptElement -> HTMLDocument (again)
+
+        To address the issue, I updated Document::commonTeardown() to clear all its ScriptRunner's pending scripts, right after
+        we stop all ActiveDOMObjects. At this point, we no longer want to run script and clearing any pending scripts is critical
+        since they hold a strong reference to the Document.
+
+        I have validated the fix on haaretz.co.il since I wasn't able to write an automated
+        test for this.
+
+        * dom/Document.cpp:
+        (WebCore::Document::commonTeardown):
+        * dom/ScriptRunner.cpp:
+        (WebCore::ScriptRunner::clearPendingScripts):
+        * dom/ScriptRunner.h:
+
 2022-03-10  Chris Fleizach  <[email protected]>
 
         AX: Support updated WebSpeech API

Modified: trunk/Source/WebCore/dom/Document.cpp (291126 => 291127)


--- trunk/Source/WebCore/dom/Document.cpp	2022-03-10 21:25:37 UTC (rev 291126)
+++ trunk/Source/WebCore/dom/Document.cpp	2022-03-10 21:27:29 UTC (rev 291127)
@@ -830,6 +830,8 @@
             resizeObserver->disconnect();
     }
 
+    scriptRunner().clearPendingScripts();
+
     if (m_highlightRegister)
         m_highlightRegister->clear();
     if (m_fragmentHighlightRegister)

Modified: trunk/Source/WebCore/dom/ScriptRunner.cpp (291126 => 291127)


--- trunk/Source/WebCore/dom/ScriptRunner.cpp	2022-03-10 21:25:37 UTC (rev 291126)
+++ trunk/Source/WebCore/dom/ScriptRunner.cpp	2022-03-10 21:27:29 UTC (rev 291127)
@@ -141,4 +141,11 @@
     }
 }
 
+void ScriptRunner::clearPendingScripts()
+{
+    m_scriptsToExecuteInOrder.clear();
+    m_scriptsToExecuteSoon.clear();
+    m_pendingAsyncScripts.clear();
 }
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/dom/ScriptRunner.h (291126 => 291127)


--- trunk/Source/WebCore/dom/ScriptRunner.h	2022-03-10 21:25:37 UTC (rev 291126)
+++ trunk/Source/WebCore/dom/ScriptRunner.h	2022-03-10 21:27:29 UTC (rev 291127)
@@ -55,6 +55,8 @@
 
     void documentFinishedParsing();
 
+    void clearPendingScripts();
+
 private:
     void timerFired();
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to