ASSERT(registration || isTerminating()) hit in SWServerWorker::skipWaiting()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Jan 2018 19:13:54 +0000 (19:13 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Jan 2018 19:13:54 +0000 (19:13 +0000)
commitff47bba031b805e54c705c08622986ed67590594
tree21e913cfbfddd551a202dd2a876681d89189e26f
parent89b52171c7212921630fffd281a245b88df8bb58
ASSERT(registration || isTerminating()) hit in SWServerWorker::skipWaiting()
https://bugs.webkit.org/show_bug.cgi?id=181761
<rdar://problem/36594564>

Reviewed by Youenn Fablet.

There is a short period of time, early in the registration process where a
SWServerWorker object exists for a registration but is not in the registration's
installing/waiting/active slots yet. As a result, if a registration is cleared
during this period (for e.g. due to the user clearing all website data), that
SWServerWorker will not be terminated. We then hit assertion later on when this
worker is trying to do things (like call skipWaiting).

To address the issue, we now keep a reference this SWServerWorker on the
registration, via a new SWServerRegistration::m_preInstallationWorker data member.
When the registration is cleared, we now take care of terminating this worker.

No new tests, covered by existing tests that crash flakily in debug builds.

* workers/WorkerThread.cpp:
(WebCore::WorkerThread::stop):
if the mutex is locked, then the worker thread is still starting. We spin the
runloop and try to stop again later. This avoids the deadlock shown in
Bug 181763 as the worker thread may need to interact with the main thread
during startup.

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::installContextData):
* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::scriptContextFailedToStart):
(WebCore::SWServerJobQueue::install):
* workers/service/server/SWServerRegistration.cpp:
(WebCore::SWServerRegistration::~SWServerRegistration):
(WebCore::SWServerRegistration::setPreInstallationWorker):
(WebCore::SWServerRegistration::clear):
* workers/service/server/SWServerRegistration.h:
(WebCore::SWServerRegistration::preInstallationWorker const):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227221 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/workers/WorkerThread.cpp
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServerJobQueue.cpp
Source/WebCore/workers/service/server/SWServerRegistration.cpp
Source/WebCore/workers/service/server/SWServerRegistration.h