Title: [285587] trunk/Source/WebCore
- Revision
- 285587
- Author
- [email protected]
- Date
- 2021-11-10 09:51:15 -0800 (Wed, 10 Nov 2021)
Log Message
imported/w3c/web-platform-tests/webmessaging/broadcastchannel/workers.html is flaky crashing in debug
https://bugs.webkit.org/show_bug.cgi?id=232920
Reviewed by Alex Christensen.
When WorkerGlobalScope::postTask() gets called, the task may get destroyed on the worker thread, without
getting executed in the case where the worker thread is about to exit. This was causing trouble in
BroadcastChannel::dispatchMessageTo() where we were calling WorkerGlobalScope::postTask() and capturing
a CallbackAggregator. We were relying on the task actually executing to dispatch the CallbackAggregator
back to the maint thread so that the completion handler is always called on the main thread.
To address the issue, we now capture a WTF::ScopeExit which calls the completion handler on the main
thread upon destruction. This way, the completion handler will always get called on the main thread,
no matter what.
* dom/BroadcastChannel.cpp:
(WebCore::BroadcastChannel::dispatchMessageTo):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (285586 => 285587)
--- trunk/Source/WebCore/ChangeLog 2021-11-10 17:42:35 UTC (rev 285586)
+++ trunk/Source/WebCore/ChangeLog 2021-11-10 17:51:15 UTC (rev 285587)
@@ -1,3 +1,23 @@
+2021-11-10 Chris Dumez <[email protected]>
+
+ imported/w3c/web-platform-tests/webmessaging/broadcastchannel/workers.html is flaky crashing in debug
+ https://bugs.webkit.org/show_bug.cgi?id=232920
+
+ Reviewed by Alex Christensen.
+
+ When WorkerGlobalScope::postTask() gets called, the task may get destroyed on the worker thread, without
+ getting executed in the case where the worker thread is about to exit. This was causing trouble in
+ BroadcastChannel::dispatchMessageTo() where we were calling WorkerGlobalScope::postTask() and capturing
+ a CallbackAggregator. We were relying on the task actually executing to dispatch the CallbackAggregator
+ back to the maint thread so that the completion handler is always called on the main thread.
+
+ To address the issue, we now capture a WTF::ScopeExit which calls the completion handler on the main
+ thread upon destruction. This way, the completion handler will always get called on the main thread,
+ no matter what.
+
+ * dom/BroadcastChannel.cpp:
+ (WebCore::BroadcastChannel::dispatchMessageTo):
+
2021-11-10 Enrique Ocaña González <[email protected]>
[GTK] Layout Test media/video-seek-with-negative-playback.html timeouts on the release bot.
Modified: trunk/Source/WebCore/dom/BroadcastChannel.cpp (285586 => 285587)
--- trunk/Source/WebCore/dom/BroadcastChannel.cpp 2021-11-10 17:42:35 UTC (rev 285586)
+++ trunk/Source/WebCore/dom/BroadcastChannel.cpp 2021-11-10 17:51:15 UTC (rev 285587)
@@ -38,6 +38,7 @@
#include <wtf/HashMap.h>
#include <wtf/IsoMallocInlines.h>
#include <wtf/MainThread.h>
+#include <wtf/Scope.h>
namespace WebCore {
@@ -208,12 +209,15 @@
void BroadcastChannel::dispatchMessageTo(BroadcastChannelIdentifier channelIdentifier, Ref<SerializedScriptValue>&& message, CompletionHandler<void()>&& completionHandler)
{
ASSERT(isMainThread());
+ auto completionHandlerCallingScope = makeScopeExit([completionHandler = WTFMove(completionHandler)]() mutable {
+ callOnMainThread(WTFMove(completionHandler));
+ });
+
auto contextIdentifier = channelToContextIdentifier().get(channelIdentifier);
if (!contextIdentifier)
- return completionHandler();
+ return;
- auto callbackAggregator = CallbackAggregator::create(WTFMove(completionHandler));
- ScriptExecutionContext::ensureOnContextThread(contextIdentifier, [channelIdentifier, message = WTFMove(message), callbackAggregator = WTFMove(callbackAggregator)](auto&) mutable {
+ ScriptExecutionContext::ensureOnContextThread(contextIdentifier, [channelIdentifier, message = WTFMove(message), completionHandlerCallingScope = WTFMove(completionHandlerCallingScope)](auto&) mutable {
RefPtr<BroadcastChannel> channel;
{
Locker locker { allBroadcastChannelsLock };
@@ -221,8 +225,6 @@
}
if (channel)
channel->dispatchMessage(WTFMove(message));
-
- callOnMainThread([callbackAggregator = WTFMove(callbackAggregator)] { });
});
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes