We should be able to terminate service workers that are unresponsive
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Jan 2018 00:57:42 +0000 (00:57 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Jan 2018 00:57:42 +0000 (00:57 +0000)
commit909a51b58cd9abcf254493b05fc77f9a3873c005
tree220a3d2dfc551b4fc1e1e78bba20f57330a14df4
parent73f375737e8057233fce651479915d2581b1767f
We should be able to terminate service workers that are unresponsive
https://bugs.webkit.org/show_bug.cgi?id=181563
<rdar://problem/35280031>

Reviewed by Alex Christensen.

Source/WebCore:

Test: http/tests/workers/service/postmessage-after-terminating-hung-worker.html

* workers/service/context/SWContextManager.cpp:
(WebCore::SWContextManager::terminateWorker):
Before calling WorkerThread::stop(), set a timer with the given timeout parameter.
If the worker thread has not stopped when the timer fires, forcefully exit the
service worker process. The StorageProcess will take care of relaunching the
service worker process if it exits abruptly.

(WebCore::SWContextManager::serviceWorkerFailedToTerminate):
Log error message if we failed to terminate a service worker and call exit().

(WebCore::SWContextManager::ServiceWorkerTerminationRequest::ServiceWorkerTerminationRequest):

* workers/service/context/SWContextManager.h:

Source/WebKit:

* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::terminateWorker):
Use a 10 second timeout for forcefully exiting the service worker process when
the service worker in question fails to terminate.

(WebKit::WebSWContextManagerConnection::syncTerminateWorker):
Use a 100ms timeout for forcefully exiting the service worker process when
the service worker in question fails to terminate. This method is only called
from the layout tests, which is why we use a very short timeout.

Source/WTF:

* wtf/ObjectIdentifier.h:
(WTF::ObjectIdentifier::loggingString const):
Allow using loggingString() from RELEASE_LOG().

LayoutTests:

Add layout test coverage.

* http/tests/workers/service/postmessage-after-terminating-hung-worker-expected.txt: Added.
* http/tests/workers/service/postmessage-after-terminating-hung-worker.html: Added.
* http/tests/workers/service/resources/postmessage-after-terminating-hung-worker.js: Added.
* http/tests/workers/service/resources/postmessage-echo-worker-mayhang.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227174 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/workers/service/postmessage-after-terminating-hung-worker-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/postmessage-after-terminating-hung-worker.html [new file with mode: 0644]
LayoutTests/http/tests/workers/service/resources/postmessage-after-terminating-hung-worker.js [new file with mode: 0644]
LayoutTests/http/tests/workers/service/resources/postmessage-echo-worker-mayhang.js [new file with mode: 0644]
Source/WTF/ChangeLog
Source/WTF/wtf/ObjectIdentifier.h
Source/WebCore/ChangeLog
Source/WebCore/workers/service/context/SWContextManager.cpp
Source/WebCore/workers/service/context/SWContextManager.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp