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

Unified Diff: third_party/WebKit/Source/core/workers/WorkerThread.cpp

Issue 2046483002: Worker: Protect a running debugger task from forcible worker termination (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@avoid_debugger_task
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/workers/WorkerThread.cpp
diff --git a/third_party/WebKit/Source/core/workers/WorkerThread.cpp b/third_party/WebKit/Source/core/workers/WorkerThread.cpp
index c862eb2915d0f5aec5188a86ed7df6ea9eb4089b..4c9fd41c6bf49d98dd87d6148515aaf77e919bc4 100644
--- a/third_party/WebKit/Source/core/workers/WorkerThread.cpp
+++ b/third_party/WebKit/Source/core/workers/WorkerThread.cpp
@@ -351,6 +351,14 @@ void WorkerThread::terminateInternal(TerminationMode mode)
// If terminate has already been called.
if (m_terminated) {
+ if (m_runningDebuggerTask) {
+ // Any debugger task is guaranteed to finish, so we can wait for the
+ // completion even if the synchronous forcible termination is
+ // requested. Shutdown sequence will start after the task.
+ DCHECK(!m_scheduledForceTerminationTask);
+ return;
+ }
+
// The synchronous forcible termination request should overtake the
// scheduled termination task because the request will block the main
// thread and the scheduled termination task never runs.
@@ -385,7 +393,7 @@ void WorkerThread::terminateInternal(TerminationMode mode)
// loop. If script execution weren't forbidden, a while(1) loop in JS could
// keep the thread alive forever.
//
- // (1) |m_readyToShutdown|: It this is set, the worker thread has already
+ // (1) |m_readyToShutdown|: If this is set, the worker thread has already
// noticed that the thread is about to be terminated and the worker global
// scope is already disposed, so we don't have to explicitly terminate the
// worker execution.
@@ -581,11 +589,13 @@ void WorkerThread::performDebuggerTaskOnWorkerThread(std::unique_ptr<CrossThread
ThreadDebugger::idleStarted(isolate());
{
MutexLocker lock(m_threadStateMutex);
- m_runningDebuggerTask = false;
-
- if (!m_terminated)
+ if (!m_terminated) {
+ m_runningDebuggerTask = false;
return;
+ }
// terminate() was called. Shutdown sequence will start soon.
+ // Keep |m_runningDebuggerTask| to prevent forcible termination from the
+ // main thread before shutdown preparation.
}
// Stop further worker tasks to run after this point.
prepareForShutdownOnWorkerThread();
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkerThread.h ('k') | third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698