Make Document::postTask() safe to call from a background thread.
Created attachment 373657 [details] Patch
Here is an example of legit case where we're calling Document::postTask() from a background thread: Thread 16 Crashed:: WebCore: Worker 0 com.apple.JavaScriptCore 0x000000057173035e WTFCrash + 14 (Assertions.cpp:305) 1 com.apple.WebCore 0x0000000559f463eb WTFCrashWithInfo(int, char const*, char const*, int) + 27 2 com.apple.WebCore 0x000000055b6e114c WebCore::ContainerNode::WeakValueType* WTF::WeakPtrImpl::get<WebCore::ContainerNode>() + 140 (WeakPtr.h:65) 3 com.apple.WebCore 0x000000055b6e0f7a WTF::WeakPtrFactory<WebCore::ContainerNode>::createWeakPtr(WebCore::ContainerNode&) const + 138 (WeakPtr.h:142) 4 com.apple.WebCore 0x000000055b6d70ff WTF::WeakPtr<WebCore::Document> WTF::makeWeakPtr<WebCore::Document>(WebCore::Document&) + 63 (WeakPtr.h:212) 5 com.apple.WebCore 0x000000055c4a21a0 WebCore::Document::postTask(WebCore::ScriptExecutionContext::Task&&) + 32 (Document.cpp:6121) 6 com.apple.WebCore 0x000000055de23635 WebCore::WorkerMessagingProxy::reportPendingActivity(bool) + 101 (WorkerMessagingProxy.cpp:283) 7 com.apple.WebCore 0x000000055de01793 WebCore::DedicatedWorkerThread::runEventLoop() + 83 (DedicatedWorkerThread.cpp:57) 8 com.apple.WebCore 0x000000055de27710 WebCore::WorkerThread::workerThread() + 1184 (WorkerThread.cpp:206) 9 com.apple.WebCore 0x000000055de37c58 WebCore::WorkerThread::start(WTF::Function<void (WTF::String const&)>&&)::$_12::operator()() const + 24 (WorkerThread.cpp:150) 10 com.apple.WebCore 0x000000055de37c19 WTF::Detail::CallableWrapper<WebCore::WorkerThread::start(WTF::Function<void (WTF::String const&)>&&)::$_12, void>::call() + 25 (Function.h:52) 11 com.apple.JavaScriptCore 0x000000057175ad6a WTF::Function<void ()>::operator()() const + 138 (Function.h:79) 12 com.apple.JavaScriptCore 0x00000005717f22f0 WTF::Thread::entryPoint(WTF::Thread::NewThreadContext*) + 416 (Threading.cpp:149) 13 com.apple.JavaScriptCore 0x00000005717fa725 WTF::wtfThreadEntryPoint(void*) + 21 (ThreadingPOSIX.cpp:200) 14 libsystem_pthread.dylib 0x00007fff6dd36daa _pthread_start + 125 15 libsystem_pthread.dylib 0x00007fff6dd336af thread_start + 15
Comment on attachment 373657 [details] Patch Maybe we should add some assertions in makeWeakPtr to make sure it's not called from the wrong thread anywhere else.
(In reply to Alex Christensen from comment #3) > Comment on attachment 373657 [details] > Patch > > Maybe we should add some assertions in makeWeakPtr to make sure it's not > called from the wrong thread anywhere else. Well, this is what I am doing in Bug 199517, and this is how I found this bug (and several others already).
Comment on attachment 373657 [details] Patch Clearing flags on attachment: 373657 Committed r247239: <https://trac.webkit.org/changeset/247239>
All reviewed patches have been landed. Closing bug.
<rdar://problem/52805445>
Comment on attachment 373657 [details] Patch Nice catch!