Bug 256200

Summary: [Win] StreamServerConnection is leaking Connection in GPU process
Product: WebKit Reporter: Fujii Hironori <Hironori.Fujii>
Component: WebKit2Assignee: Fujii Hironori <Hironori.Fujii>
Status: RESOLVED FIXED    
Severity: Normal CC: kkinnunen, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
connection-leak-debug-logging.patch
none
Adding Sleep
none
WIP patch none

Description Fujii Hironori 2023-05-02 00:23:05 PDT
[Win] StreamServerConnection is leaking Connection in GPU process

1. Apply he debug logging patch and build WinCairo Debug
2. Start WinCairo MiniBrowser in a debugger
3. Go to https://get.webgl.org/
4. Click reload button several times

Actual: The number of Connection objects in GPU process is gradually increasing.
Expected: The number of Connection objects in GPU process shouldn't gradually increasing.
Comment 1 Fujii Hironori 2023-05-02 00:23:38 PDT
Created attachment 466169 [details]
connection-leak-debug-logging.patch
Comment 2 Fujii Hironori 2023-05-02 01:11:50 PDT
Created attachment 466170 [details]
Adding Sleep

Adding Sleep() in Connection::dispatchDidCloseAndInvalidate works around the problem.
Comment 3 Fujii Hironori 2023-05-07 17:57:52 PDT
Created attachment 466267 [details]
WIP patch

Connection::dispatchDidCloseAndInvalidate is using Connection::dispatchToClient.
However, Connection::dispatchToClient doesn't work in the RemoteGraphicsContextGL work queue because the thread isn't using RunLoop.
This problem can be fixed by using RunLoop::main() instead of using RunLoop::current() in the RemoteGraphicsContextGL work queue.
Comment 4 Fujii Hironori 2023-05-07 17:59:57 PDT
But, this patch introduces a new assertion failure for comment#0's steps.

ASSERTION FAILED: this == &current()
C:\home\webkit\gb\Source\WTF\wtf\RunLoop.cpp(209) : WTF::RunLoop::assertIsCurrent
1   00007FFEB60B26FB WTFCrash
2   00007FFEB60B77FD WTFCrashWithInfo
3   00007FFEB615C73D WTF::RunLoop::assertIsCurrent
4   00007FFE78E0D6EA WTF::assertIsCurrent
5   00007FFE78DF1B1F IPC::Connection::dispatcher
6   00007FFE78DEC3C8 IPC::Connection::invalidate
7   00007FFE78E31FE3 IPC::StreamServerConnection::invalidate
8   00007FFE788EF905 WebKit::RemoteGraphicsContextGL::workQueueUninitialize
9   00007FFE788F10AF `WebKit::RemoteGraphicsContextGL::stopListeningForIPC'::`2'::<lambda_1>::operator()
10  00007FFE788F288B WTF::Detail::CallableWrapper<`WebKit::RemoteGraphicsContextGL::stopListeningForIPC'::`2'::<lambda_1>,void>::call
11  00007FFE77E0D554 WTF::Function<void __cdecl(void)>::operator()
12  00007FFE78E33C08 IPC::StreamConnectionWorkQueue::processStreams
13  00007FFE78E33E95 `IPC::StreamConnectionWorkQueue::startProcessingThread'::`2'::<lambda_1>::operator()
14  00007FFE78E343CB WTF::Detail::CallableWrapper<`IPC::StreamConnectionWorkQueue::startProcessingThread'::`2'::<lambda_1>,void>::call
15  00007FFEB60C9D93 WTF::Function<void __cdecl(void)>::operator()
16  00007FFEB616B558 WTF::Thread::entryPoint
17  00007FFEB6244BC4 WTF::wtfThreadEntryPoint
18  00007FFF6B761BB2 configthreadlocale
19  00007FFF6D4B7604 BaseThreadInitThunk
20  00007FFF6D9226A1 RtlUserThreadStart
Comment 5 Fujii Hironori 2023-05-07 18:06:03 PDT
Adding Sleep() works around the leakage problem (comment#2).
Connection::invalidate is called in the other thread during the sleep.
Connection::dispatchToClient does nothing after invalidated.
Comment 6 Fujii Hironori 2023-05-07 22:11:28 PDT
Pull request: https://github.com/WebKit/WebKit/pull/13562
Comment 7 Radar WebKit Bug Importer 2023-05-09 00:24:21 PDT
<rdar://problem/109082171>
Comment 8 Fujii Hironori 2023-05-24 12:45:31 PDT
264465@main (bug#249769) fixed the problem.