The cleanup task will invoke workerGlobalScope.clearScript() which deletes the WorkerScriptController. Hence, it is not safe for WorkerThread::stop() to access the script controller after it has posted the cleanup task.
FYI, this issue was found by a test: https://build.webkit.org/results/Apple%20Sierra%20Release%20WK1%20(Tests)/r216684%20(1509)/results.html
Created attachment 309792 [details] proposed patch. Let's get some EWS testing first.
Looks like there are many crashes and failures on worker tests.
Comment on attachment 309792 [details] proposed patch. Attachment 309792 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/3721396 New failing tests: crypto/workers/subtle/hrsa-postMessage-worker.html workers/bomb.html imported/w3c/web-platform-tests/resource-timing/rt-serialization.html performance-api/performance-observer-basic.html
Created attachment 309806 [details] Archive of layout-test-results from ews103 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews103 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Comment on attachment 309792 [details] proposed patch. Attachment 309792 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.webkit.org/results/3721411 New failing tests: crypto/workers/subtle/rsa-postMessage-worker.html fetch/header-constructor-is-array.html
Created attachment 309809 [details] Archive of layout-test-results from ews107 for mac-elcapitan-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews107 Port: mac-elcapitan-wk2 Platform: Mac OS X 10.11.6
Comment on attachment 309792 [details] proposed patch. I'm investigating the failures.
r216677 has been rolled out. This bug is no longer needed. Will rework the original fix in https://bugs.webkit.org/show_bug.cgi?id=171775. *** This bug has been marked as a duplicate of bug 171775 ***