Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Issue 2280523002: Worker: Unify worker thread shutdown sequence (Closed)

Created:
4 years, 4 months ago by nhiroki
Modified:
4 years, 3 months ago
Reviewers:
haraken, yhirano
CC:
chromium-reviews, blink-reviews, falken, kinuko+worker_chromium.org, blink-worker-reviews_chromium.org, horo+watch_chromium.org
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Worker: Unify worker thread shutdown sequences. This CL unifies worker thread shutdown sequences to fix a crash and simplify shutdown. <Problem> When termination is requested on the main thread before WorkerThread is initialized on the worker thread, shutdown sequence runs in a different way from regular shutdown sequence: initialization sequence seamlessly switches to shutdown sequence and asks the main thread to destroy WorkerThread (see WorkerThread::initializeOnWorkerThread). This causes a crash in a following scenario: 1) Request to start the worker thread from the main thread. 2) Post a task to the worker thread from the main thread. 3) Request to terminate the worker thread from the main thread. 4) Start initialziation sequence and switch to shutdown sequence on the worker thread. 5) WorkerThread is destroyed on the main thread. 6) The posted task runs on the worker thread and crashes. <Solution> This CL makes the initialization sequence complete regardless of termination request and defer to the regular shutdown task posted from the main thread. Other tasks also posted from the main thread(*) are guaranteed to be drained until the shutdown task runs. <Appendix> Regarding (*), you might wonder if tasks posted from/to the worker thread cannot be guaranteed to be drained until the shutdown tasks run. This case is covered by other mechanism. Let's consider it in following 2 cases: 1) An uninitialized worker thread does not post a task to itself, so there should be no tasks when termination happens before initialization. 2) Otherwise, WorkerBackingThread::shutdown drains all tasks. Therefore, we can ensure that tasks posted from the worker thread also never run after shutdown. BUG=632810, 640843 Committed: https://crrev.com/cfa01627d191d2a1a801943994f287b8cf5b1c42 Cr-Commit-Position: refs/heads/master@{#420592}

Patch Set 1 #

Total comments: 2

Patch Set 2 : unconditionally initialize worker thread #

Total comments: 2

Patch Set 3 : address yhirano's comment #

Total comments: 3

Patch Set 4 : rebase #

Patch Set 5 : update comments #

Patch Set 6 : rebase #

Patch Set 7 : ready to review #

Patch Set 8 : tweak #

Unified diffs Side-by-side diffs Delta from patch set Stats (+41 lines, -58 lines) Patch
M third_party/WebKit/Source/core/workers/WorkerThread.h View 1 2 3 4 5 6 7 2 chunks +6 lines, -2 lines 0 comments Download
M third_party/WebKit/Source/core/workers/WorkerThread.cpp View 1 2 3 4 5 6 7 11 chunks +26 lines, -47 lines 0 comments Download
M third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp View 1 2 3 4 5 6 7 3 chunks +9 lines, -9 lines 0 comments Download

Messages

Total messages: 71 (55 generated)
nhiroki
PTAL, thanks!
4 years, 4 months ago (2016-08-25 07:25:01 UTC) #19
haraken
LGTM. Great CL description. If it's very rare that a worker thread is requested to ...
4 years, 3 months ago (2016-08-25 08:04:32 UTC) #20
nhiroki
Thank you for reviewing. On 2016/08/25 08:04:32, haraken wrote: > LGTM. Great CL description. > ...
4 years, 3 months ago (2016-08-25 08:43:27 UTC) #21
nhiroki
Updated. Can you take another look? Thanks. https://codereview.chromium.org/2280523002/diff/40001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/2280523002/diff/40001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode535 third_party/WebKit/Source/core/workers/WorkerThread.cpp:535: if (m_exitCode ...
4 years, 3 months ago (2016-08-26 06:47:55 UTC) #27
haraken
This looks much simpler! LGTM.
4 years, 3 months ago (2016-08-26 07:32:52 UTC) #28
yhirano
https://codereview.chromium.org/2280523002/diff/60001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/2280523002/diff/60001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode408 third_party/WebKit/Source/core/workers/WorkerThread.cpp:408: bool shouldScheduleToTerminateExecution = (m_threadState == ThreadState::Running) && !m_runningDebuggerTask; IIUC ...
4 years, 3 months ago (2016-08-29 06:56:20 UTC) #31
nhiroki
Thank you for your comment. PTAL. https://codereview.chromium.org/2280523002/diff/60001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/2280523002/diff/60001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode408 third_party/WebKit/Source/core/workers/WorkerThread.cpp:408: bool shouldScheduleToTerminateExecution = ...
4 years, 3 months ago (2016-08-30 01:52:31 UTC) #34
nhiroki
On 2016/08/30 01:52:31, nhiroki wrote: > Thank you for your comment. PTAL. > > https://codereview.chromium.org/2280523002/diff/60001/third_party/WebKit/Source/core/workers/WorkerThread.cpp ...
4 years, 3 months ago (2016-08-30 04:57:18 UTC) #38
yhirano
https://codereview.chromium.org/2280523002/diff/100001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/2280523002/diff/100001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode511 third_party/WebKit/Source/core/workers/WorkerThread.cpp:511: prepareForShutdownOnWorkerThread(); Sorry I don't understand why this call is ...
4 years, 3 months ago (2016-08-30 05:00:45 UTC) #39
nhiroki
I just resumed this CL. Sorry for my delayed reply. https://codereview.chromium.org/2280523002/diff/100001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/2280523002/diff/100001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode511 ...
4 years, 3 months ago (2016-09-06 08:35:11 UTC) #40
nhiroki
On 2016/08/30 04:57:18, nhiroki wrote: > On 2016/08/30 01:52:31, nhiroki wrote: > > Thank you ...
4 years, 3 months ago (2016-09-07 05:38:50 UTC) #41
nhiroki
yhirano@, sorry for taking a long time. The test failures are now fixed. Can you ...
4 years, 3 months ago (2016-09-23 06:54:46 UTC) #59
yhirano
lgtm
4 years, 3 months ago (2016-09-23 06:58:03 UTC) #60
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2280523002/220001
4 years, 3 months ago (2016-09-23 07:41:48 UTC) #67
commit-bot: I haz the power
Committed patchset #8 (id:220001)
4 years, 3 months ago (2016-09-23 11:29:48 UTC) #69
commit-bot: I haz the power
4 years, 3 months ago (2016-09-23 11:33:17 UTC) #71
Message was sent while issue was closed.
Patchset 8 (id:??) landed as
https://crrev.com/cfa01627d191d2a1a801943994f287b8cf5b1c42
Cr-Commit-Position: refs/heads/master@{#420592}

Powered by Google App Engine
This is Rietveld 408576698