Bug 42826 - Crash in thread pool because WorkQueue keeps waiting on closed HANDLEs
Summary: Crash in thread pool because WorkQueue keeps waiting on closed HANDLEs
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows XP
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar, PlatformOnly
Depends on: 43150
Blocks:
  Show dependency treegraph
 
Reported: 2010-07-22 08:17 PDT by Adam Roben (:aroben)
Modified: 2010-09-08 14:45 PDT (History)
5 users (show)

See Also:


Attachments
Teach WorkQueue how to stop waiting on objects on Windows (8.48 KB, patch)
2010-08-27 12:35 PDT, Adam Roben (:aroben)
no flags Details | Formatted Diff | Diff
Teach WorkQueue how to stop waiting on objects on Windows (10.85 KB, patch)
2010-09-08 13:50 PDT, Adam Roben (:aroben)
andersca: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Roben (:aroben) 2010-07-22 08:17:04 PDT
There's no way to tell WorkQueue to stop waiting on a particular HANDLE. This means that users of WorkQueue either have to leak their HANDLEs (yuck) or close their HANDLEs while WorkQueue is still waiting on them, which leads to crashes in WaitForMultipleObjects (also yuck).

We should add a way to tell WorkQueue to stop waiting on a particular handle so that it can be closed.
Comment 1 Adam Roben (:aroben) 2010-07-22 08:30:42 PDT
It's possible that this is a cause of bug 42785. See discussion in that bug for more details.
Comment 2 Adam Roben (:aroben) 2010-07-22 08:31:49 PDT
<rdar://problem/8222253>
Comment 3 Adam Roben (:aroben) 2010-07-22 08:39:15 PDT
See bug 42785 comments 1 through 8.
Comment 4 Adam Roben (:aroben) 2010-07-22 08:40:41 PDT
(In reply to bug 42785 comment #8)
> I think using a pair of events will work. The first event will be used to tell the work queue thread to stop waiting. The second event will be used to tell the main thread that waiting has stopped.

Anders informed me that this is not a good strategy. Waiting on the work queue thread is dangerous because the work queue thread might wait on the first thread, resulting in a deadlock.

I think adding an unregisterAndCloseHandle function to WorkQueue might be the way to go. We'd add the handle to a m_handlesToClose Vector and signal m_performWorkEvent. Then the work queue thread would close all handles in m_handlesToClose when it wakes up.
Comment 5 Adam Roben (:aroben) 2010-07-26 14:00:45 PDT
Fixing this doesn't seem to fix bug 42785.
Comment 6 Adam Roben (:aroben) 2010-08-18 10:16:08 PDT
*** Bug 43148 has been marked as a duplicate of this bug. ***
Comment 7 Adam Roben (:aroben) 2010-08-18 14:56:00 PDT
I've been working on switching over to using an I/O completion port in WorkQueue. This would make it unnecessary to unregister a HANDLE; you can just close it and stop worrying.

However, I'm seeing spurious reads in the web process. I.e., the web process will request 1 byte of the next message from the pipe, and then will be told that 207 bytes were read. This doesn't make any sense! Windows shouldn't be reading more than we asked it to; where would it store the data?
Comment 8 Adam Roben (:aroben) 2010-08-27 12:26:32 PDT
I'm going to base the fix for this on the fix for bug 43150.
Comment 9 Adam Roben (:aroben) 2010-08-27 12:35:47 PDT
Created attachment 65752 [details]
Teach WorkQueue how to stop waiting on objects on Windows
Comment 10 Adam Roben (:aroben) 2010-08-27 14:41:07 PDT
Comment on attachment 65752 [details]
Teach WorkQueue how to stop waiting on objects on Windows

This patch introduces a crash due to WorkItemWin being destroyed when it is currently being used in handleCallback.

To fix this we shouldn't destroy the WorkItemWin until we've unregistered the wait.
Comment 11 Adam Roben (:aroben) 2010-09-08 13:50:32 PDT
Created attachment 66933 [details]
Teach WorkQueue how to stop waiting on objects on Windows
Comment 12 Adam Roben (:aroben) 2010-09-08 14:19:03 PDT
Committed r67013: <http://trac.webkit.org/changeset/67013>
Comment 13 WebKit Review Bot 2010-09-08 14:45:52 PDT
http://trac.webkit.org/changeset/67013 might have broken Qt Linux Release
The following changes are on the blame list:
http://trac.webkit.org/changeset/67013
http://trac.webkit.org/changeset/67014