New issue
Advanced search Search tips

Issue 641215 link

Starred by 0 users

Issue metadata

Status: Fixed
Owner:
Closed: Sep 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug

Blocking:
issue 638877



Sign in to add a comment

Remove isTerminating() calls from Streams code

Project Member Reported by nhiroki@chromium.org, Aug 26 2016

Issue description

isTerminating() was added as a workaround by this change:
https://chromium.googlesource.com/chromium/src/+/bef901ae9100f30e3ee2fb185c4197a2de55e4c1

Note that simply removing the function does not work. See the original report on issue 640521
 
Blocking: 638877
Cc: -nhiroki@chromium.org yhirano@chromium.org
Components: Blink>Workers
Owner: nhiroki@chromium.org
I suspect that a service worker is forcibly terminated by WorkerThread::ForceTerminationTask while a stream is being processed.

Random ideas (MT: Main Thread, WT: Worker Thread):

A) We could prolong the delay of the task to reduce the cases. Prolonging the delay may block graceful renderer process shutdown, but the shutdown sequence will be removed soon (issue 639244) and it shouldn't be a matter.

B) A task may run on WT after forcible termination task runs on MT in the following scenario:
  1) MT posts a long-running task (> 2 sec) to WT.
  2) MT posts a normal task to WT.
  3) MT requests to terminate and schedules a forcible termination task.
  4) After a while, the forcible termination task runs on MT and terminates Isolate.
  5) The normal task runs on MT, accesses V8 API and crashes.
Probably MT should notify forcible termination of the worker thread at the step 4) or WT should check Isolate::IsExecutionTerminating() on performTaskOnWorkerThread().
modules/fetch related code posts a task without using core/worker code (see https://cs.chromium.org/chromium/src/content/child/shared_memory_data_consumer_handle.cc?q=SharedMemoryData&sq=package:chromium&l=461). Hence it's hard to ignore such tasks uniformally by modifying core/worker code.
We can call prepareForShutdown in didProcessTask if the forcible termination has been requested. That triggers ActiveDOMObject::stop in the worker thread.
Cc: -yhirano@chromium.org nhiroki@chromium.org
Owner: yhirano@chromium.org
Status: Started (was: Assigned)
Reg: c#4, that sounds like a good idea :)

(Reassigned this to yhirano@ because he has some patches)
Project Member

Comment 6 by bugdroid1@chromium.org, Sep 6 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/c71893f933af16266912649fb1543043323609b7

commit c71893f933af16266912649fb1543043323609b7
Author: yhirano <yhirano@chromium.org>
Date: Tue Sep 06 00:07:10 2016

[Worker] Call contextDestroyed in shutdown preparation

WorkerOrWorkletGlobalScope::notifyContextDestroyed is currently
called in performShutdownTask, but it is generally good to notify that
earlier.

BUG= 641215 

Review-Url: https://codereview.chromium.org/2305603002
Cr-Commit-Position: refs/heads/master@{#416568}

[modify] https://crrev.com/c71893f933af16266912649fb1543043323609b7/third_party/WebKit/Source/core/workers/WorkerThread.cpp

Project Member

Comment 7 by bugdroid1@chromium.org, Sep 6 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/7a2a29de535c01c40ef8ee11621064572676e61d

commit 7a2a29de535c01c40ef8ee11621064572676e61d
Author: yhirano <yhirano@chromium.org>
Date: Tue Sep 06 06:56:36 2016

[Worker] Call prepareForShutdown ASAP when terminated forcibly

When a worker is terminated forcibly (i.e., TerminateExecution
is called), it is possible that many tasks are preceding
performShutdownOnWorkerThread on the worker task queue. As the v8 context
is in an invalid state, we need to ask worker objects to stop working
before executing all the queued tasks.

BUG= 641215 

Review-Url: https://codereview.chromium.org/2299883006
Cr-Commit-Position: refs/heads/master@{#416598}

[modify] https://crrev.com/7a2a29de535c01c40ef8ee11621064572676e61d/third_party/WebKit/Source/core/loader/ThreadableLoaderTest.cpp
[modify] https://crrev.com/7a2a29de535c01c40ef8ee11621064572676e61d/third_party/WebKit/Source/core/workers/WorkerThread.cpp

Project Member

Comment 9 by bugdroid1@chromium.org, Sep 9 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/7875b88ecfc01daa437a59dd9ff5b9fa32d15a29

commit 7875b88ecfc01daa437a59dd9ff5b9fa32d15a29
Author: yhirano <yhirano@chromium.org>
Date: Fri Sep 09 04:22:37 2016

Remove isTerminating checks from ReadableStreamOperations

BUG= 641215 

Review-Url: https://codereview.chromium.org/2319013006
Cr-Commit-Position: refs/heads/master@{#417502}

[modify] https://crrev.com/7875b88ecfc01daa437a59dd9ff5b9fa32d15a29/third_party/WebKit/Source/core/streams/ReadableStreamOperations.cpp

Status: Fixed (was: Started)
Looks like #8 and #9 didn't cause a lot of crashes.
Yay! \o/

Sign in to add a comment