Chromium Code Reviews
Help | Chromium Project | Gerrit Changes | Sign in
(115)

Issue 1184833002: Fix a race condition during worker thread initialization (Closed)

Created:
4 years, 10 months ago by Sami
Modified:
4 years, 10 months ago
Reviewers:
kinuko, sadrul
CC:
blink-reviews, kinuko+worker_chromium.org, horo+watch_chromium.org, falken, alex clarke (OOO till 29th), Takashi Toyoshima
Target Ref:
refs/heads/master
Project:
blink
Visibility:
Public.

Description

Fix a race condition during worker thread initialization This patch fixes a race condition which can result in a worker thread accessing freed memory during its initialization. One possible sequence of events is: 1. The main thread creates the worker thread and posts a task to run WorkerThread::initialize(). 2. Immediately after this, the main thread calls WorkerThread::terminateAndWait() to shut down the worker thread. 3. WorkerThread::terminateAndWait() notices that the worker hasn't initialized yet and signals m_terminationEvent. 4. The caller of terminateAndWait() assumes that the WorkerThread has been terminated and deallocates either the WorkerThread itself or some object that it depends on. 5. Finally, WorkerThread::initialize starts to run on the worker thread, accessing memory freed in step #4. The fix is to always signal m_terminationEvent from the worker thread to guarantee that we don't think the thread terminated before it actually did. BUG=499153 Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=197196

Patch Set 1 #

Patch Set 2 : Add a test. #

Patch Set 3 : Fixed the test. #

Total comments: 2

Patch Set 4 : AnyNumber => AtMost #

Unified diffs Side-by-side diffs Delta from patch set Stats (+33 lines, -12 lines) Patch
M Source/core/workers/WorkerThread.cpp View 1 2 chunks +6 lines, -4 lines 0 comments Download
M Source/core/workers/WorkerThreadTest.cpp View 1 2 3 8 chunks +27 lines, -8 lines 0 comments Download

Messages

Total messages: 14 (5 generated)
Sami
Hi, does this look plausible?-) I can sort of reproduce the crash if I add ...
4 years, 10 months ago (2015-06-12 18:02:34 UTC) #2
kinuko
Yes, this fix looks plausible. I think I once suggested something like this in https://code.google.com/p/chromium/issues/detail?id=492592#c6 ...
4 years, 10 months ago (2015-06-13 22:55:28 UTC) #3
Sami
On 2015/06/13 22:55:28, kinuko wrote: > Yes, this fix looks plausible. > > I think ...
4 years, 10 months ago (2015-06-15 20:18:25 UTC) #4
kinuko
lgtm, thanks! https://codereview.chromium.org/1184833002/diff/40001/Source/core/workers/WorkerThreadTest.cpp File Source/core/workers/WorkerThreadTest.cpp (right): https://codereview.chromium.org/1184833002/diff/40001/Source/core/workers/WorkerThreadTest.cpp#newcode233 Source/core/workers/WorkerThreadTest.cpp:233: EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Times(AnyNumber()); AnyNumber() -> AtMostOne(1) ?
4 years, 10 months ago (2015-06-16 01:35:19 UTC) #5
Sami
https://codereview.chromium.org/1184833002/diff/40001/Source/core/workers/WorkerThreadTest.cpp File Source/core/workers/WorkerThreadTest.cpp (right): https://codereview.chromium.org/1184833002/diff/40001/Source/core/workers/WorkerThreadTest.cpp#newcode233 Source/core/workers/WorkerThreadTest.cpp:233: EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Times(AnyNumber()); On 2015/06/16 01:35:19, kinuko wrote: > AnyNumber() ...
4 years, 10 months ago (2015-06-16 16:03:45 UTC) #6
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1184833002/60001
4 years, 10 months ago (2015-06-16 16:04:03 UTC) #9
commit-bot: I haz the power
Try jobs failed on following builders: win_blink_rel on tryserver.blink (JOB_FAILED, http://build.chromium.org/p/tryserver.blink/builders/win_blink_rel/builds/66824)
4 years, 10 months ago (2015-06-16 18:09:34 UTC) #11
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1184833002/60001
4 years, 10 months ago (2015-06-16 20:16:19 UTC) #13
commit-bot: I haz the power
4 years, 10 months ago (2015-06-16 21:13:05 UTC) #14
Message was sent while issue was closed.
Committed patchset #4 (id:60001) as
https://src.chromium.org/viewvc/blink?view=rev&revision=197196

Powered by Google App Engine
This is Rietveld 408576698