Title: [272132] releases/WebKitGTK/webkit-2.30
- Revision
- 272132
- Author
- [email protected]
- Date
- 2021-02-01 02:20:00 -0800 (Mon, 01 Feb 2021)
Log Message
Merge r270496 - [GLib] Leaked RunLoop objects on worker threads
https://bugs.webkit.org/show_bug.cgi?id=219232
<rdar://problem/71772277>
Patch by Zan Dobersek <[email protected]> on 2020-12-07
Reviewed by Geoffrey Garen.
Source/WTF:
During the thread-local RunLoop::Holder destruction, explicitly clear out
the iteration Deque objects on the held RunLoop, destroying any Function
objects that never got to execute on this thread. Generally, this allows
for any RunLoop reference stored in these objects to be released.
Specifically, this would allow for destruction of the RunLoop::Timer
object that's queued up in the JSRunLoopTimer::Manager::PerVMData
destructor but never gets dispatched because the thread (a JS worker) is
shut down before that happens. Destruction of the timer will release the
reference of the RunLoop that's held by the RunLoop::Holder, finally
enabling the RunLoop object itself be destroyed once the RunLoop::Holder
reference is let go.
* wtf/RunLoop.cpp:
(WTF::RunLoop::Holder::~Holder):
(WTF::RunLoop::threadWillExit):
* wtf/RunLoop.h:
Tools:
Add a unit test covering proper RunLoop teardown upon thread destruction
even if RunLoop references are stored in the dispatch queues.
* TestWebKitAPI/Tests/WTF/RunLoop.cpp:
(TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: releases/WebKitGTK/webkit-2.30/Source/WTF/ChangeLog (272131 => 272132)
--- releases/WebKitGTK/webkit-2.30/Source/WTF/ChangeLog 2021-02-01 10:19:55 UTC (rev 272131)
+++ releases/WebKitGTK/webkit-2.30/Source/WTF/ChangeLog 2021-02-01 10:20:00 UTC (rev 272132)
@@ -1,3 +1,29 @@
+2020-12-07 Zan Dobersek <[email protected]>
+
+ [GLib] Leaked RunLoop objects on worker threads
+ https://bugs.webkit.org/show_bug.cgi?id=219232
+ <rdar://problem/71772277>
+
+ Reviewed by Geoffrey Garen.
+
+ During the thread-local RunLoop::Holder destruction, explicitly clear out
+ the iteration Deque objects on the held RunLoop, destroying any Function
+ objects that never got to execute on this thread. Generally, this allows
+ for any RunLoop reference stored in these objects to be released.
+
+ Specifically, this would allow for destruction of the RunLoop::Timer
+ object that's queued up in the JSRunLoopTimer::Manager::PerVMData
+ destructor but never gets dispatched because the thread (a JS worker) is
+ shut down before that happens. Destruction of the timer will release the
+ reference of the RunLoop that's held by the RunLoop::Holder, finally
+ enabling the RunLoop object itself be destroyed once the RunLoop::Holder
+ reference is let go.
+
+ * wtf/RunLoop.cpp:
+ (WTF::RunLoop::Holder::~Holder):
+ (WTF::RunLoop::threadWillExit):
+ * wtf/RunLoop.h:
+
2020-11-03 Stephan Szabo <[email protected]>
[WinCairo/PlayStation] ICU 68.1 no longer exposes FALSE and TRUE macros by default
Modified: releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/RunLoop.cpp (272131 => 272132)
--- releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/RunLoop.cpp 2021-02-01 10:19:55 UTC (rev 272131)
+++ releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/RunLoop.cpp 2021-02-01 10:20:00 UTC (rev 272132)
@@ -46,6 +46,11 @@
{
}
+ ~Holder()
+ {
+ m_runLoop->threadWillExit();
+ }
+
RunLoop& runLoop() { return m_runLoop; }
private:
@@ -162,4 +167,10 @@
wakeUp();
}
+void RunLoop::threadWillExit()
+{
+ m_currentIteration.clear();
+ m_nextIteration.clear();
+}
+
} // namespace WTF
Modified: releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/RunLoop.h (272131 => 272132)
--- releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/RunLoop.h 2021-02-01 10:19:55 UTC (rev 272131)
+++ releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/RunLoop.h 2021-02-01 10:20:00 UTC (rev 272132)
@@ -96,6 +96,8 @@
enum class CycleResult { Continue, Stop };
WTF_EXPORT_PRIVATE CycleResult static cycle(RunLoopMode = DefaultRunLoopMode);
+ WTF_EXPORT_PRIVATE void threadWillExit();
+
#if USE(GLIB_EVENT_LOOP)
WTF_EXPORT_PRIVATE GMainContext* mainContext() const { return m_mainContext.get(); }
enum class Event { WillDispatch, DidDispatch };
Modified: releases/WebKitGTK/webkit-2.30/Tools/ChangeLog (272131 => 272132)
--- releases/WebKitGTK/webkit-2.30/Tools/ChangeLog 2021-02-01 10:19:55 UTC (rev 272131)
+++ releases/WebKitGTK/webkit-2.30/Tools/ChangeLog 2021-02-01 10:20:00 UTC (rev 272132)
@@ -1,3 +1,17 @@
+2020-12-07 Zan Dobersek <[email protected]>
+
+ [GLib] Leaked RunLoop objects on worker threads
+ https://bugs.webkit.org/show_bug.cgi?id=219232
+ <rdar://problem/71772277>
+
+ Reviewed by Geoffrey Garen.
+
+ Add a unit test covering proper RunLoop teardown upon thread destruction
+ even if RunLoop references are stored in the dispatch queues.
+
+ * TestWebKitAPI/Tests/WTF/RunLoop.cpp:
+ (TestWebKitAPI::TEST):
+
2020-11-18 Michael Catanzaro <[email protected]>
[WPE][GTK] Update Outlook user agent quirk
Modified: releases/WebKitGTK/webkit-2.30/Tools/TestWebKitAPI/Tests/WTF/RunLoop.cpp (272131 => 272132)
--- releases/WebKitGTK/webkit-2.30/Tools/TestWebKitAPI/Tests/WTF/RunLoop.cpp 2021-02-01 10:19:55 UTC (rev 272131)
+++ releases/WebKitGTK/webkit-2.30/Tools/TestWebKitAPI/Tests/WTF/RunLoop.cpp 2021-02-01 10:20:00 UTC (rev 272132)
@@ -215,4 +215,21 @@
})->waitForCompletion();
}
+TEST(WTF_RunLoop, ThreadTerminationSelfReferenceCleanup)
+{
+ RefPtr<RunLoop> runLoop;
+
+ Thread::create("RunLoopThreadTerminationSelfReferenceCleanup", [&] {
+ runLoop = makeRefPtr(RunLoop::current());
+
+ // This stores a RunLoop reference in the dispatch queue that will not be released
+ // via the usual dispatch, but should still be released upon thread termination.
+ // After that, the observing RefPtr should be the only one holding a reference
+ // to the RunLoop object.
+ runLoop->dispatch([ref = runLoop.copyRef()] { });
+ })->waitForCompletion();
+
+ EXPECT_TRUE(runLoop->hasOneRef());
+}
+
} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes