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

Issue 1978163002: Worker: Initiate worker thread shutdown always on the main thread (Closed)

Created:
4 years, 7 months ago by nhiroki
Modified:
4 years, 7 months ago
Reviewers:
kinuko, yhirano
CC:
chromium-reviews, blink-reviews, kinuko+worker_chromium.org, falken, blink-worker-reviews_chromium.org, horo+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Worker: Initiate worker thread shutdown always on the main thread In the current implementation, worker shutdown can be initiated twice on WorkerMicrotaskRunner::didProcessTask() when close() is called on {Dedicated,Shared}WorkerGlobalScope: 1. WorkerReportingProxy::workerGlobalScopeClosed() eventually calls WorkerThread::terminate() on the main thread (see call pathes below). 2. WorkerThread::terminateFromWorkerThread() is directly called on the worker thread. These are valid because the shutdown sequence actually does not run twice thanks to the thread-safe WorkerThread::m_shutdown flag. However, to achieve the thread shutdown observation mechanism (see the issue), it would be better to initiate the shutdown always on the main thread. For that, this CL removes the shutdown call from the worker thread and just prepare shutdown instead. APPENDIX: Thread termination sequence via workerGlobalScopeClosed() on each worker mechanism: // DedicatedWorker InProcessWorkerObjectProxy::workerGlobalScopeClosed() InProcessWorkerMessagingProxy::terminateWorkerGlobalScope() m_workerThread->terminate(); // SharedWorker WebSharedWorkerImpl::workerGlobalScopeClosed() WebSharedWorkerImpl::workerGlobalScopeClosedOnMainThread() WebSharedWorkerImpl::terminateWorkerThread() m_workerThread->terminate(); // ServiceWorker does not support close() ServiceWorkerGlobalScopeProxy::workerGlobalScopeClosed() NOTREACHED() BUG=487050, 575532 Committed: https://crrev.com/2d6728fa52504193b1c511a4f675894e2d56e2e1 Cr-Commit-Position: refs/heads/master@{#395600}

Patch Set 1 #

Patch Set 2 : remake #

Total comments: 11

Patch Set 3 : address review comments #

Total comments: 4

Patch Set 4 : rebase #

Patch Set 5 : rebase #

Patch Set 6 : post two tasks (prepareForShutdown and performShutdownTask) #

Total comments: 12

Patch Set 7 : address kinuko's comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+73 lines, -65 lines) Patch
M third_party/WebKit/Source/core/workers/WorkerThread.h View 1 2 3 4 5 3 chunks +15 lines, -12 lines 0 comments Download
M third_party/WebKit/Source/core/workers/WorkerThread.cpp View 1 2 3 4 5 6 7 chunks +58 lines, -53 lines 0 comments Download

Messages

Total messages: 39 (19 generated)
nhiroki
PTAL, thanks!
4 years, 7 months ago (2016-05-16 04:59:28 UTC) #9
nhiroki
On 2016/05/16 04:59:28, nhiroki wrote: > PTAL, thanks! Hmm..., apparently this CL is not complete ...
4 years, 7 months ago (2016-05-16 21:45:56 UTC) #11
nhiroki
The patchset 2 is now ready to review. PTAL, thanks!
4 years, 7 months ago (2016-05-20 02:06:10 UTC) #15
kinuko
https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode78 third_party/WebKit/Source/core/workers/WorkerThread.cpp:78: // Dispose WorkerGlobalScope to avoid processing the next task. ...
4 years, 7 months ago (2016-05-20 15:19:30 UTC) #17
nhiroki
Thank you for reviewing! Comment replies only (not updated yet). https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode78 ...
4 years, 7 months ago (2016-05-23 01:32:27 UTC) #18
nhiroki
https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode349 third_party/WebKit/Source/core/workers/WorkerThread.cpp:349: if (m_shutdown) On 2016/05/20 15:19:29, kinuko wrote: > Do ...
4 years, 7 months ago (2016-05-23 06:21:58 UTC) #19
kinuko
https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode78 third_party/WebKit/Source/core/workers/WorkerThread.cpp:78: // Dispose WorkerGlobalScope to avoid processing the next task. ...
4 years, 7 months ago (2016-05-23 09:35:26 UTC) #20
yhirano
https://codereview.chromium.org/1978163002/diff/40001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/1978163002/diff/40001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode245 third_party/WebKit/Source/core/workers/WorkerThread.cpp:245: DCHECK(isCurrentThread()); It might be good to assert m_terminated && ...
4 years, 7 months ago (2016-05-23 10:05:19 UTC) #21
nhiroki
Thank you for reviewing! Updated. PTAL :) https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode78 third_party/WebKit/Source/core/workers/WorkerThread.cpp:78: // Dispose ...
4 years, 7 months ago (2016-05-24 06:50:43 UTC) #22
yhirano
lgtm
4 years, 7 months ago (2016-05-24 07:30:23 UTC) #23
kinuko
https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/1978163002/diff/20001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode78 third_party/WebKit/Source/core/workers/WorkerThread.cpp:78: // Dispose WorkerGlobalScope to avoid processing the next task. ...
4 years, 7 months ago (2016-05-24 09:07:49 UTC) #24
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1978163002/120001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1978163002/120001
4 years, 7 months ago (2016-05-24 12:29:48 UTC) #27
nhiroki
Thank you! Updated. https://codereview.chromium.org/1978163002/diff/100001/third_party/WebKit/Source/core/workers/WorkerThread.cpp File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right): https://codereview.chromium.org/1978163002/diff/100001/third_party/WebKit/Source/core/workers/WorkerThread.cpp#newcode77 third_party/WebKit/Source/core/workers/WorkerThread.cpp:77: // Dispose WorkerGlobalScope to avoid processing ...
4 years, 7 months ago (2016-05-24 13:36:06 UTC) #28
commit-bot: I haz the power
Dry run: This issue passed the CQ dry run.
4 years, 7 months ago (2016-05-24 13:52:20 UTC) #30
kinuko
lgtm (It'd be nice if we could have tests that could test some shutdown corner-cases.. ...
4 years, 7 months ago (2016-05-24 14:49:10 UTC) #31
nhiroki
On 2016/05/24 14:49:10, kinuko wrote: > lgtm > > (It'd be nice if we could ...
4 years, 7 months ago (2016-05-24 15:15:08 UTC) #32
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1978163002/120001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1978163002/120001
4 years, 7 months ago (2016-05-24 15:17:36 UTC) #35
commit-bot: I haz the power
Committed patchset #7 (id:120001)
4 years, 7 months ago (2016-05-24 15:21:10 UTC) #36
commit-bot: I haz the power
Patchset 7 (id:??) landed as https://crrev.com/2d6728fa52504193b1c511a4f675894e2d56e2e1 Cr-Commit-Position: refs/heads/master@{#395600}
4 years, 7 months ago (2016-05-24 15:23:25 UTC) #38
nhiroki
4 years, 7 months ago (2016-05-25 01:58:34 UTC) #39
Message was sent while issue was closed.
JFYI

https://codereview.chromium.org/1978163002/diff/100001/third_party/WebKit/Sou...
File third_party/WebKit/Source/core/workers/WorkerThread.cpp (right):

https://codereview.chromium.org/1978163002/diff/100001/third_party/WebKit/Sou...
third_party/WebKit/Source/core/workers/WorkerThread.cpp:234: void
WorkerThread::performShutdownTask()
On 2016/05/24 13:36:06, nhiroki wrote:
> On 2016/05/24 09:07:48, kinuko wrote:
> > nit: maybe we could rename this to performShutdown() (method renaming /
> > reordering could be done in a follow-up cleanup CL too)
> 
> I'll make a separate CL.

Uploaded a CL: https://codereview.chromium.org/2015453002/

https://codereview.chromium.org/1978163002/diff/100001/third_party/WebKit/Sou...
File third_party/WebKit/Source/core/workers/WorkerThread.h (right):

https://codereview.chromium.org/1978163002/diff/100001/third_party/WebKit/Sou...
third_party/WebKit/Source/core/workers/WorkerThread.h:79: void
prepareForShutdown();
On 2016/05/24 13:36:06, nhiroki wrote:
> On 2016/05/24 09:07:49, kinuko wrote:
> > nit: could we make WorkerMicroTaskRunner a private inner class of
WorkerThread
> > and make this method private as well?  I don't feel this needs to be a
public
> > method.
> 
> Agreed. I'll make a separate CL for this.

Uploaded a CL: https://codereview.chromium.org/2006273003/

Powered by Google App Engine
This is Rietveld 408576698