Title: [276379] trunk
Revision
276379
Author
[email protected]
Date
2021-04-21 11:47:52 -0700 (Wed, 21 Apr 2021)

Log Message

ASSERTION FAILED: context().isInitialized() ./Modules/webaudio/OfflineAudioDestinationNode.cpp(142)
https://bugs.webkit.org/show_bug.cgi?id=224876
<rdar://76896256>

Reviewed by Eric Carlson.

Source/WebCore:

In OfflineAudioDestinationNode::uninitialize(), we were synchronizing with the
render thread to make sure that OfflineAudioDestinationNode::offlineRender() was
done running before proceeding with uninitialization. However, when an audio
worklet is used, m_renderThread is null and no synchronization with the AudioWorklet
thread would happen. This patch adds the missing synchronization with the AudioWorklet
thread when present.

Test: webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash.html

* Modules/webaudio/OfflineAudioDestinationNode.cpp:
(WebCore::OfflineAudioDestinationNode::uninitialize):

LayoutTests:

Add layout test coverage.

* webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash-expected.txt: Added.
* webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (276378 => 276379)


--- trunk/LayoutTests/ChangeLog	2021-04-21 18:34:18 UTC (rev 276378)
+++ trunk/LayoutTests/ChangeLog	2021-04-21 18:47:52 UTC (rev 276379)
@@ -1,3 +1,16 @@
+2021-04-21  Chris Dumez  <[email protected]>
+
+        ASSERTION FAILED: context().isInitialized() ./Modules/webaudio/OfflineAudioDestinationNode.cpp(142)
+        https://bugs.webkit.org/show_bug.cgi?id=224876
+        <rdar://76896256>
+
+        Reviewed by Eric Carlson.
+
+        Add layout test coverage.
+
+        * webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash-expected.txt: Added.
+        * webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash.html: Added.
+
 2021-04-21  Simon Fraser  <[email protected]>
 
         will-change: transform should affect nested position:fixed

Added: trunk/LayoutTests/webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash-expected.txt (0 => 276379)


--- trunk/LayoutTests/webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash-expected.txt	2021-04-21 18:47:52 UTC (rev 276379)
@@ -0,0 +1 @@
+This test passes if it does not crash.

Added: trunk/LayoutTests/webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash.html (0 => 276379)


--- trunk/LayoutTests/webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash.html	                        (rev 0)
+++ trunk/LayoutTests/webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash.html	2021-04-21 18:47:52 UTC (rev 276379)
@@ -0,0 +1,27 @@
+<p>This test passes if it does not crash.</p>
+<script>
+  if (window.testRunner)
+    testRunner.dumpAsText();
+
+  _onload_ = async () => {
+    let contexts = [];
+    _onunload_ = () => {
+      while (contexts.length) {
+        let ctx = contexts.pop();
+        ctx.startRendering();
+      }
+    };
+
+    for (let i = 0; i < 15; i++) {
+      let offlineAudioContext = new OfflineAudioContext({
+        length: 1,
+        sampleRate: 3000
+      });
+      contexts.push(offlineAudioContext);
+      try {
+        await offlineAudioContext.audioWorklet.addModule('');
+      } catch {
+      }
+    }
+  };
+</script>

Modified: trunk/Source/WebCore/ChangeLog (276378 => 276379)


--- trunk/Source/WebCore/ChangeLog	2021-04-21 18:34:18 UTC (rev 276378)
+++ trunk/Source/WebCore/ChangeLog	2021-04-21 18:47:52 UTC (rev 276379)
@@ -1,3 +1,23 @@
+2021-04-21  Chris Dumez  <[email protected]>
+
+        ASSERTION FAILED: context().isInitialized() ./Modules/webaudio/OfflineAudioDestinationNode.cpp(142)
+        https://bugs.webkit.org/show_bug.cgi?id=224876
+        <rdar://76896256>
+
+        Reviewed by Eric Carlson.
+
+        In OfflineAudioDestinationNode::uninitialize(), we were synchronizing with the
+        render thread to make sure that OfflineAudioDestinationNode::offlineRender() was
+        done running before proceeding with uninitialization. However, when an audio
+        worklet is used, m_renderThread is null and no synchronization with the AudioWorklet
+        thread would happen. This patch adds the missing synchronization with the AudioWorklet
+        thread when present.
+
+        Test: webaudio/OfflineAudioContext/offlineaudiocontext-uninitialized-crash.html
+
+        * Modules/webaudio/OfflineAudioDestinationNode.cpp:
+        (WebCore::OfflineAudioDestinationNode::uninitialize):
+
 2021-04-21  Simon Fraser  <[email protected]>
 
         will-change: transform should affect nested position:fixed

Modified: trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp (276378 => 276379)


--- trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp	2021-04-21 18:34:18 UTC (rev 276378)
+++ trunk/Source/WebCore/Modules/webaudio/OfflineAudioDestinationNode.cpp	2021-04-21 18:47:52 UTC (rev 276379)
@@ -38,6 +38,7 @@
 #include <algorithm>
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/MainThread.h>
+#include <wtf/threads/BinarySemaphore.h>
  
 namespace WebCore {
 
@@ -76,9 +77,18 @@
     if (!isInitialized())
         return;
 
-    if (m_renderThread) {
-        m_renderThread->waitForCompletion();
-        m_renderThread = nullptr;
+    if (m_startedRendering) {
+        if (m_renderThread) {
+            m_renderThread->waitForCompletion();
+            m_renderThread = nullptr;
+        }
+        if (auto* workletProxy = context().audioWorklet().proxy()) {
+            BinarySemaphore semaphore;
+            workletProxy->postTaskForModeToWorkletGlobalScope([&semaphore](ScriptExecutionContext&) mutable {
+                semaphore.signal();
+            }, WorkerRunLoop::defaultMode());
+            semaphore.wait();
+        }
     }
 
     AudioNode::uninitialize();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to