- Revision
- 186006
- Author
- an...@apple.com
- Date
- 2015-06-26 12:21:02 -0700 (Fri, 26 Jun 2015)
Log Message
Network process hangs fetching disk cache entries
https://bugs.webkit.org/show_bug.cgi?id=146348
<rdar://problem/21528072>
Reviewed by Anders Carlsson.
RunLoop::dispatch may deadlock if invoked with std::function that captures an object that calls RunLoop::dispatch in destructor.
* wtf/RunLoop.cpp:
(WTF::RunLoop::performWork):
Don't reuse std::function variable in loop. We may end up destroying previously held std::function in assignment
while holding the runloop mutex. With this change std::function is always destroyed with mutex unlocked.
Modified Paths
Added Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (186005 => 186006)
--- trunk/Source/WTF/ChangeLog 2015-06-26 18:26:19 UTC (rev 186005)
+++ trunk/Source/WTF/ChangeLog 2015-06-26 19:21:02 UTC (rev 186006)
@@ -1,3 +1,19 @@
+2015-06-26 Antti Koivisto <an...@apple.com>
+
+ Network process hangs fetching disk cache entries
+ https://bugs.webkit.org/show_bug.cgi?id=146348
+ <rdar://problem/21528072>
+
+ Reviewed by Anders Carlsson.
+
+ RunLoop::dispatch may deadlock if invoked with std::function that captures an object that calls RunLoop::dispatch in destructor.
+
+ * wtf/RunLoop.cpp:
+ (WTF::RunLoop::performWork):
+
+ Don't reuse std::function variable in loop. We may end up destroying previously held std::function in assignment
+ while holding the runloop mutex. With this change std::function is always destroyed with mutex unlocked.
+
2015-06-24 Commit Queue <commit-qu...@webkit.org>
Unreviewed, rolling out r185906.
Modified: trunk/Source/WTF/wtf/RunLoop.cpp (186005 => 186006)
--- trunk/Source/WTF/wtf/RunLoop.cpp 2015-06-26 18:26:19 UTC (rev 186005)
+++ trunk/Source/WTF/wtf/RunLoop.cpp 2015-06-26 19:21:02 UTC (rev 186006)
@@ -88,22 +88,24 @@
// By only handling up to the number of functions that were in the queue when performWork() is called
// we guarantee to occasionally return from the run loop so other event sources will be allowed to spin.
- std::function<void()> function;
size_t functionsToHandle = 0;
-
{
- MutexLocker locker(m_functionQueueLock);
- functionsToHandle = m_functionQueue.size();
+ std::function<void()> function;
+ {
+ MutexLocker locker(m_functionQueueLock);
+ functionsToHandle = m_functionQueue.size();
- if (m_functionQueue.isEmpty())
- return;
+ if (m_functionQueue.isEmpty())
+ return;
- function = m_functionQueue.takeFirst();
+ function = m_functionQueue.takeFirst();
+ }
+
+ function();
}
- function();
-
for (size_t functionsHandled = 1; functionsHandled < functionsToHandle; ++functionsHandled) {
+ std::function<void()> function;
{
MutexLocker locker(m_functionQueueLock);
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (186005 => 186006)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2015-06-26 18:26:19 UTC (rev 186005)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2015-06-26 19:21:02 UTC (rev 186006)
@@ -299,6 +299,7 @@
E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
E19DB9791B32137C00DB38D4 /* NavigatorLanguage.mm in Sources */ = {isa = PBXBuildFile; fileRef = E19DB9781B32137C00DB38D4 /* NavigatorLanguage.mm */; };
E40019331ACE9B88001B0A2A /* BloomFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40019301ACE9B5C001B0A2A /* BloomFilter.cpp */; };
+ E4C9ABC91B3DB2C40040A987 /* RunLoop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */; };
F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */; };
F660AA1515A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA1415A61ABF003A1243 /* InjectedBundleInitializationUserDataCallbackWins_Bundle.cpp */; };
F6B7BE9517469212008A3445 /* DidAssociateFormControls_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6B7BE92174691EF008A3445 /* DidAssociateFormControls_Bundle.cpp */; };
@@ -727,6 +728,7 @@
E40019301ACE9B5C001B0A2A /* BloomFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BloomFilter.cpp; sourceTree = "<group>"; };
E490296714E2E3A4002BEDD1 /* TypingStyleCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TypingStyleCrash.mm; sourceTree = "<group>"; };
E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Deque.cpp; sourceTree = "<group>"; };
+ E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; };
F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback.cpp; sourceTree = "<group>"; };
F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback_Bundle.cpp; sourceTree = "<group>"; };
@@ -1096,6 +1098,7 @@
86BD19971A2DB05B006DCF0A /* RefCounter.cpp */,
93A427AD180DA60F00CD24D7 /* RefLogger.h */,
93A427A8180D9B0700CD24D7 /* RefPtr.cpp */,
+ E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */,
14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */,
CD5393C91757BAC400C07123 /* SHA1.cpp */,
81B50192140F232300D9EB58 /* StringBuilder.cpp */,
@@ -1527,6 +1530,7 @@
7CCE7F4C1A411B9800447C4C /* OSObjectPtr.cpp in Sources */,
7CCE7F071A411AE600447C4C /* PageLoadBasic.cpp in Sources */,
7CCE7F081A411AE600447C4C /* PageLoadDidChangeLocationWithinPageForFrame.cpp in Sources */,
+ E4C9ABC91B3DB2C40040A987 /* RunLoop.cpp in Sources */,
7CCE7EC71A411A7E00447C4C /* PageVisibilityStateWithWindowChanges.mm in Sources */,
7CCE7F091A411AE600447C4C /* ParentFrame.cpp in Sources */,
7CCE7F0A1A411AE600447C4C /* PasteboardNotifications.mm in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/RunLoop.cpp (0 => 186006)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/RunLoop.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/RunLoop.cpp 2015-06-26 19:21:02 UTC (rev 186006)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "PlatformUtilities.h"
+#include <wtf/RunLoop.h>
+
+namespace TestWebKitAPI {
+
+static bool testFinished;
+static int count = 100;
+
+TEST(WTF_RunLoop, Deadlock)
+{
+ RunLoop::initializeMainRunLoop();
+
+ struct DispatchFromDestructorTester {
+ ~DispatchFromDestructorTester() {
+ RunLoop::main().dispatch([] {
+ if (!(--count))
+ testFinished = true;
+ });
+ }
+ };
+
+ for (int i = 0; i < count; ++i) {
+ auto capture = std::make_shared<DispatchFromDestructorTester>();
+ RunLoop::main().dispatch([capture] { });
+ }
+
+ Util::run(&testFinished);
+}
+
+} // namespace TestWebKitAPI