<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>181763</bug_id>
          
          <creation_ts>2018-01-17 13:56:43 -0800</creation_ts>
          <short_desc>Possible deadlock when terminating a worker</short_desc>
          <delta_ts>2018-01-17 14:18:11 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Service Workers</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>181761</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Chris Dumez">cdumez</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>beidson</cc>
    
    <cc>ggaren</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1390199</commentid>
    <comment_count>0</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2018-01-17 13:56:43 -0800</bug_when>
    <thetext>Deadlock:

Main thread:
    2778 Thread_12836086   DispatchQueue_1: com.apple.main-thread  (serial)
    + 2778 start  (in libdyld.dylib) + 1  [0x7fff64e21115]
    +   2778 main  (in com.apple.WebKit.WebContent.Development) + 1195  [0x10a36513b]  XPCServiceMain.mm:148
    +     2778 xpc_main  (in libxpc.dylib) + 417  [0x7fff650ed082]
    +       2778 _xpc_objc_main  (in libxpc.dylib) + 580  [0x7fff650ee42f]
    +         2778 NSApplicationMain  (in AppKit) + 804  [0x7fff3a932f1a]
    +           2778 -[NSApplication run]  (in AppKit) + 764  [0x7fff3a963d6d]
    +             2778 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]  (in AppKit) + 3044  [0x7fff3b104b4c]
    +               2778 _DPSNextEvent  (in AppKit) + 2085  [0x7fff3a96ef5f]
    +                 2778 _BlockUntilNextEventMatchingListInModeWithFilter  (in HIToolbox) + 64  [0x7fff3c6a3914]
    +                   2778 ReceiveNextEventCommon  (in HIToolbox) + 613  [0x7fff3c6a3b96]
    +                     2778 RunCurrentEventLoopInMode  (in HIToolbox) + 286  [0x7fff3c6a3e26]
    +                       2778 CFRunLoopRunSpecific  (in CoreFoundation) + 487  [0x7fff3d3963d7]
    +                         2778 __CFRunLoopRun  (in CoreFoundation) + 1293  [0x7fff3d396b7d]
    +                           2778 __CFRunLoopDoSources0  (in CoreFoundation) + 208  [0x7fff3d397700]
    +                             2778 __CFRunLoopDoSource0  (in CoreFoundation) + 108  [0x7fff3d46c39c]
    +                               2778 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__  (in CoreFoundation) + 17  [0x7fff3d3b4711]
    +                                 2778 WTF::RunLoop::performWork(void*)  (in JavaScriptCore) + 36  [0x7a865a074]  RunLoopCF.cpp:38
    +                                   2778 WTF::RunLoop::performWork()  (in JavaScriptCore) + 445  [0x7a86598bd]  RunLoop.cpp:123
    +                                     2778 WTF::Function&lt;void ()&gt;::operator()() const  (in JavaScriptCore) + 139  [0x7a86148fb]  Function.h:56
    +                                       2778 WTF::Function&lt;void ()&gt;::CallableWrapper&lt;IPC::Connection::enqueueIncomingMessage(std::__1::unique_ptr&lt;IPC::Decoder, std::__1::default_delete&lt;IPC::Decoder&gt; &gt;)::$_14&gt;::call()  (in WebKit) + 25  [0x10a4de459]  Function.h:101
    +                                         2778 IPC::Connection::enqueueIncomingMessage(std::__1::unique_ptr&lt;IPC::Decoder, std::__1::default_delete&lt;IPC::Decoder&gt; &gt;)::$_14::operator()()  (in WebKit) + 29  [0x10a4de4fd]  Connection.cpp:895
    +                                           2778 IPC::Connection::dispatchOneMessage()  (in WebKit) + 1530  [0x10a4c603a]  Connection.cpp:959
    +                                             2778 IPC::Connection::dispatchMessage(std::__1::unique_ptr&lt;IPC::Decoder, std::__1::default_delete&lt;IPC::Decoder&gt; &gt;)  (in WebKit) + 712  [0x10a4bb0b8]  Connection.cpp:928
    +                                               2778 IPC::Connection::dispatchMessage(IPC::Decoder&amp;)  (in WebKit) + 51  [0x10a4c5a33]  Connection.cpp:901
    +                                                 2778 WebKit::WebToStorageProcessConnection::didReceiveMessage(IPC::Connection&amp;, IPC::Decoder&amp;)  (in WebKit) + 621  [0x10b1bc06d]  WebToStorageProcessConnection.cpp:82
    +                                                   2778 WebKit::WebSWContextManagerConnection::didReceiveMessage(IPC::Connection&amp;, IPC::Decoder&amp;)  (in WebKit) + 770  [0x10b18c192]  WebSWContextManagerConnectionMessageReceiver.cpp:103
    +                                                     2778 void IPC::handleMessage&lt;Messages::WebSWContextManagerConnection::TerminateWorker, WebKit::WebSWContextManagerConnection, void (WebKit::WebSWContextManagerConnection::*)(WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt;)&gt;(IPC::Decoder&amp;, WebKit::WebSWContextManagerConnection*, void (WebKit::WebSWContextManagerConnection::*)(WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt;))  (in WebKit) + 261  [0x10b18cf65]  HandleMessage.h:126
    +                                                       2778 void IPC::callMemberFunction&lt;WebKit::WebSWContextManagerConnection, void (WebKit::WebSWContextManagerConnection::*)(WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt;), std::__1::tuple&lt;WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt; &gt;, std::__1::integer_sequence&lt;unsigned long, 0ul&gt; &gt;(std::__1::tuple&lt;WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt; &gt;&amp;&amp;, WebKit::WebSWContextManagerConnection*, void (WebKit::WebSWContextManagerConnection::*)(WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt;))  (in WebKit) + 96  [0x10b190c00]  HandleMessage.h:46
    +                                                         2778 void IPC::callMemberFunctionImpl&lt;WebKit::WebSWContextManagerConnection, void (WebKit::WebSWContextManagerConnection::*)(WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt;), std::__1::tuple&lt;WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt; &gt;, 0ul&gt;(WebKit::WebSWContextManagerConnection*, void (WebKit::WebSWContextManagerConnection::*)(WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt;), std::__1::tuple&lt;WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt; &gt;&amp;&amp;, std::__1::integer_sequence&lt;unsigned long, 0ul&gt;)  (in WebKit) + 165  [0x10b190dc5]  HandleMessage.h:40
    +                                                           2778 WebKit::WebSWContextManagerConnection::terminateWorker(WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt;)  (in WebKit) + 63  [0x10b177f7f]  WebSWContextManagerConnection.cpp:198
    +                                                             2778 WebCore::SWContextManager::terminateWorker(WTF::ObjectIdentifier&lt;WebCore::ServiceWorkerIdentifierType&gt;, WTF::Function&lt;void ()&gt;&amp;&amp;)  (in WebCore) + 215  [0x79b356497]  SWContextManager.cpp:113
    +                                                               2778 WebCore::WorkerThread::stop(WTF::Function&lt;void ()&gt;&amp;&amp;)  (in WebCore) + 57  [0x79b2f1f29]  WorkerThread.cpp:268
    +                                                                 2778 WTF::Locker&lt;WTF::Lock&gt;::Locker(WTF::Lock&amp;)  (in WebCore) + 29  [0x79802fd8d]  Locker.h:54
    +                                                                   2778 WTF::Locker&lt;WTF::Lock&gt;::Locker(WTF::Lock&amp;)  (in WebCore) + 48  [0x7980326e0]  Locker.h:54
    +                                                                     2778 WTF::Locker&lt;WTF::Lock&gt;::lock()  (in WebCore) + 42  [0x79803272a]  Locker.h:112
    +                                                                       2778 WTF::Lock::lock()  (in WebCore) + 53  [0x79801eb55]  Lock.h:60
    +                                                                         2778 WTF::Lock::lockSlow()  (in JavaScriptCore) + 21  [0x7a8634c65]  Lock.cpp:40
    +                                                                           2778 WTF::LockAlgorithm&lt;unsigned char, (unsigned char)1, (unsigned char)2, WTF::EmptyLockHooks&lt;unsigned char&gt; &gt;::lockSlow(WTF::Atomic&lt;unsigned char&gt;&amp;)  (in JavaScriptCore) + 390  [0x7a8634df6]  LockAlgorithmInlines.h:84
    +                                                                             2778 WTF::ParkingLot::ParkResult WTF::ParkingLot::compareAndPark&lt;unsigned char, unsigned char&gt;(WTF::Atomic&lt;unsigned char&gt; const*, unsigned char)  (in JavaScriptCore) + 85  [0x7a8197225]  ParkingLot.h:93
    +                                                                               2778 WTF::ParkingLot::ParkResult WTF::ParkingLot::parkConditionally&lt;WTF::ParkingLot::ParkResult WTF::ParkingLot::compareAndPark&lt;unsigned char, unsigned char&gt;(WTF::Atomic&lt;unsigned char&gt; const*, unsigned char)::&apos;lambda&apos;(), WTF::ParkingLot::ParkResult WTF::ParkingLot::compareAndPark&lt;unsigned char, unsigned char&gt;(WTF::Atomic&lt;unsigned char&gt; const*, unsigned char)::&apos;lambda0&apos;()&gt;(void const*, unsigned char const&amp;, unsigned char const&amp;, WTF::TimeWithDynamicClockType const&amp;)  (in JavaScriptCore) + 96  [0x7a81972e0]  ParkingLot.h:81
    +                                                                                 2778 WTF::ParkingLot::parkConditionallyImpl(void const*, WTF::ScopedLambda&lt;bool ()&gt; const&amp;, WTF::ScopedLambda&lt;void ()&gt; const&amp;, WTF::TimeWithDynamicClockType const&amp;)  (in JavaScriptCore) + 411  [0x7a864dadb]  ParkingLot.cpp:597
    +                                                                                   2778 WTF::ThreadCondition::timedWait(WTF::Mutex&amp;, double)  (in JavaScriptCore) + 104  [0x7a868ac98]  ThreadingPthreads.cpp:558
    +                                                                                     2778 WTF::ThreadCondition::wait(WTF::Mutex&amp;)  (in JavaScriptCore) + 48  [0x7a868abe0]  ThreadingPthreads.cpp:548
    +                                                                                       2778 _pthread_cond_wait  (in libsystem_pthread.dylib) + 732  [0x7fff650ad662]
    +                                                                                         2778 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff64f70cee]


Worker Thread:
    2778 Thread_12838245: WebCore: Worker
      2778 thread_start  (in libsystem_pthread.dylib) + 13  [0x7fff650abc5d]
        2778 _pthread_start  (in libsystem_pthread.dylib) + 377  [0x7fff650ac56d]
          2778 _pthread_body  (in libsystem_pthread.dylib) + 340  [0x7fff650ac6c1]
            2778 WTF::wtfThreadEntryPoint(void*)  (in JavaScriptCore) + 21  [0x7a8689e85]  ThreadingPthreads.cpp:223
              2778 WTF::Thread::entryPoint(WTF::Thread::NewThreadContext*)  (in JavaScriptCore) + 351  [0x7a868472f]  Threading.cpp:129
                2778 WTF::Function&lt;void ()&gt;::operator()() const  (in JavaScriptCore) + 139  [0x7a86148fb]  Function.h:56
                  2778 WTF::Function&lt;void ()&gt;::CallableWrapper&lt;WebCore::WorkerThread::start(WTF::Function&lt;void (WTF::String const&amp;)&gt;&amp;&amp;)::$_12&gt;::call()  (in WebCore) + 25  [0x79b303309]  Function.h:101
                    2778 WebCore::WorkerThread::start(WTF::Function&lt;void (WTF::String const&amp;)&gt;&amp;&amp;)::$_12::operator()() const  (in WebCore) + 24  [0x79b303348]  WorkerThread.cpp:144
                      2778 WebCore::WorkerThread::workerThread()  (in WebCore) + 877  [0x79b2f6e8d]  WorkerThread.cpp:168
                        2778 WebCore::ServiceWorkerThread::createWorkerGlobalScope(WebCore::URL const&amp;, WTF::String const&amp;, WTF::String const&amp;, bool, WebCore::ContentSecurityPolicyResponseHeaders const&amp;, bool, WTF::Ref&lt;WebCore::SecurityOrigin, WTF::DumbPtrTraits&lt;WebCore::SecurityOrigin&gt; &gt;&amp;&amp;, WTF::MonotonicTime, PAL::SessionID)  (in WebCore) + 433  [0x79b357f71]  ServiceWorkerThread.cpp:85
                          2778 WebCore::ServiceWorkerGlobalScope::create(WebCore::ServiceWorkerContextData const&amp;, WebCore::URL const&amp;, WTF::String const&amp;, WTF::String const&amp;, bool, WebCore::ServiceWorkerThread&amp;, WebCore::ContentSecurityPolicyResponseHeaders const&amp;, bool, WTF::Ref&lt;WebCore::SecurityOrigin, WTF::DumbPtrTraits&lt;WebCore::SecurityOrigin&gt; &gt;&amp;&amp;, WTF::MonotonicTime, WebCore::IDBClient::IDBConnectionProxy*, WebCore::SocketProvider*, PAL::SessionID)  (in WebCore) + 469  [0x79b32ff85]  ServiceWorkerGlobalScope.cpp:43
                            2778 WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(WebCore::ServiceWorkerContextData const&amp;, WebCore::URL const&amp;, WTF::String const&amp;, WTF::String const&amp;, bool, WebCore::ServiceWorkerThread&amp;, bool, WTF::Ref&lt;WebCore::SecurityOrigin, WTF::DumbPtrTraits&lt;WebCore::SecurityOrigin&gt; &gt;&amp;&amp;, WTF::MonotonicTime, WebCore::IDBClient::IDBConnectionProxy*, WebCore::SocketProvider*, PAL::SessionID)  (in WebCore) + 217  [0x79b330139]  ServiceWorkerGlobalScope.cpp:53
                              2778 WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(WebCore::ServiceWorkerContextData const&amp;, WebCore::URL const&amp;, WTF::String const&amp;, WTF::String const&amp;, bool, WebCore::ServiceWorkerThread&amp;, bool, WTF::Ref&lt;WebCore::SecurityOrigin, WTF::DumbPtrTraits&lt;WebCore::SecurityOrigin&gt; &gt;&amp;&amp;, WTF::MonotonicTime, WebCore::IDBClient::IDBConnectionProxy*, WebCore::SocketProvider*, PAL::SessionID)  (in WebCore) + 587  [0x79b3303fb]  ServiceWorkerGlobalScope.cpp:51
                                2778 WebCore::ServiceWorkerRegistration::getOrCreate(WebCore::ScriptExecutionContext&amp;, WTF::Ref&lt;WebCore::ServiceWorkerContainer, WTF::DumbPtrTraits&lt;WebCore::ServiceWorkerContainer&gt; &gt;&amp;&amp;, WebCore::ServiceWorkerRegistrationData&amp;&amp;)  (in WebCore) + 229  [0x79b32c6f5]  ServiceWorkerRegistration.cpp:49
                                  2778 WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration(WebCore::ScriptExecutionContext&amp;, WTF::Ref&lt;WebCore::ServiceWorkerContainer, WTF::DumbPtrTraits&lt;WebCore::ServiceWorkerContainer&gt; &gt;&amp;&amp;, WebCore::ServiceWorkerRegistrationData&amp;&amp;)  (in WebCore) + 45  [0x79b3327bd]  ServiceWorkerRegistration.cpp:56
                                    2778 WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration(WebCore::ScriptExecutionContext&amp;, WTF::Ref&lt;WebCore::ServiceWorkerContainer, WTF::DumbPtrTraits&lt;WebCore::ServiceWorkerContainer&gt; &gt;&amp;&amp;, WebCore::ServiceWorkerRegistrationData&amp;&amp;)  (in WebCore) + 773  [0x79b332ad5]  ServiceWorkerRegistration.cpp:67
                                      2778 WebCore::ServiceWorkerContainer::addRegistration(WebCore::ServiceWorkerRegistration&amp;)  (in WebCore) + 117  [0x79b32f3b5]  ServiceWorkerContainer.cpp:548
                                        2778 WebCore::ServiceWorkerContainer::ensureSWClientConnection()  (in WebCore) + 174  [0x79b32a0ce]  ServiceWorkerContainer.cpp:535
                                          2778 WTF::callOnMainThreadAndWait(WTF::Function&lt;void ()&gt;&amp;&amp;)  (in JavaScriptCore) + 271  [0x7a86386ff]  MainThread.cpp:236
                                            2778 void WTF::Condition::wait&lt;std::__1::unique_lock&lt;WTF::Lock&gt;, WTF::callOnMainThreadAndWait(WTF::Function&lt;void ()&gt;&amp;&amp;)::$_4&gt;(std::__1::unique_lock&lt;WTF::Lock&gt;&amp;, WTF::callOnMainThreadAndWait(WTF::Function&lt;void ()&gt;&amp;&amp;)::$_4 const&amp;)  (in JavaScriptCore) + 65  [0x7a86387e1]  Condition.h:130
                                              2778 void WTF::Condition::wait&lt;std::__1::unique_lock&lt;WTF::Lock&gt; &gt;(std::__1::unique_lock&lt;WTF::Lock&gt;&amp;)  (in JavaScriptCore) + 73  [0x7a863a4a9]  Condition.h:123
                                                2778 bool WTF::Condition::waitUntil&lt;std::__1::unique_lock&lt;WTF::Lock&gt; &gt;(std::__1::unique_lock&lt;WTF::Lock&gt;&amp;, WTF::TimeWithDynamicClockType const&amp;)  (in JavaScriptCore) + 140  [0x7a863a54c]  Condition.h:77
                                                  2778 WTF::ParkingLot::ParkResult WTF::ParkingLot::parkConditionally&lt;bool WTF::Condition::waitUntil&lt;std::__1::unique_lock&lt;WTF::Lock&gt; &gt;(std::__1::unique_lock&lt;WTF::Lock&gt;&amp;, WTF::TimeWithDynamicClockType const&amp;)::&apos;lambda&apos;(), bool WTF::Condition::waitUntil&lt;std::__1::unique_lock&lt;WTF::Lock&gt; &gt;(std::__1::unique_lock&lt;WTF::Lock&gt;&amp;, WTF::TimeWithDynamicClockType const&amp;)::&apos;lambda0&apos;()&gt;(void const*, std::__1::unique_lock&lt;WTF::Lock&gt; const&amp;, bool WTF::Condition::waitUntil&lt;std::__1::unique_lock&lt;WTF::Lock&gt; &gt;(std::__1::unique_lock&lt;WTF::Lock&gt;&amp;, WTF::TimeWithDynamicClockType const&amp;)::&apos;lambda0&apos;() const&amp;, WTF::TimeWithDynamicClockType const&amp;)  (in JavaScriptCore) + 96  [0x7a863a630]  ParkingLot.h:81
                                                    2778 WTF::ParkingLot::parkConditionallyImpl(void const*, WTF::ScopedLambda&lt;bool ()&gt; const&amp;, WTF::ScopedLambda&lt;void ()&gt; const&amp;, WTF::TimeWithDynamicClockType const&amp;)  (in JavaScriptCore) + 411  [0x7a864dadb]  ParkingLot.cpp:597
                                                      2778 WTF::ThreadCondition::timedWait(WTF::Mutex&amp;, double)  (in JavaScriptCore) + 104  [0x7a868ac98]  ThreadingPthreads.cpp:558
                                                        2778 WTF::ThreadCondition::wait(WTF::Mutex&amp;)  (in JavaScriptCore) + 48  [0x7a868abe0]  ThreadingPthreads.cpp:548
                                                          2778 _pthread_cond_wait  (in libsystem_pthread.dylib) + 732  [0x7fff650ad662]
                                                            2778 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff64f70cee]


Basically, it happens when terminating a worker that is still starting because of the m_threadCreationAndWorkerGlobalScopeMutex Mutex in WorkerThread and the callOnMainThreadAndWait() call in ServiceWorkerContainer::ensureSWClientConnection().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1390212</commentid>
    <comment_count>1</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2018-01-17 14:18:11 -0800</bug_when>
    <thetext>Patch at Bug 181761 takes care of fixing this as well.

*** This bug has been marked as a duplicate of bug 181761 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>