Title: [213228] trunk/Source/_javascript_Core
Revision
213228
Author
[email protected]
Date
2017-03-01 10:03:53 -0800 (Wed, 01 Mar 2017)

Log Message

REGRESSION(r211344): Remote Inspector: listingForAutomationTarget() is called off-main-thread, causing assertions
https://bugs.webkit.org/show_bug.cgi?id=168695
<rdar://problem/30643899>

Reviewed by Joseph Pecoraro.

The aforementioned commit added some new calls to update target listings. This causes RemoteInspector
to update some listings underneath an incoming setup message on the XPC queue, which is not a safe place
to gather listing information for RemoteAutomationTargets.

Update the listing asynchronously since we don't need it immediately. Since this really only happens when
the connection to the target is set up and shut down, we can trigger listings to be refreshed from
the async block that's called on the target's queue inside RemoteConnectionToTarget::{setup,close}.

* inspector/remote/RemoteInspector.h:
Make updateListingForTarget(unsigned) usable from RemoteConnectionToTarget.

* inspector/remote/cocoa/RemoteConnectionToTargetCocoa.mm:
(Inspector::RemoteConnectionToTarget::setup):
(Inspector::RemoteConnectionToTarget::close):
Grab the target identifier while the RemoteControllableTarget pointer is still valid,
and use it inside the block later after it may have been destructed already. If that happens,
then updateTargetListing will bail out because the targetIdentifier cannot be found in the mapping.

* inspector/remote/cocoa/RemoteInspectorCocoa.mm:
(Inspector::RemoteInspector::updateTargetListing):
We need to make sure to request a listing push after the target is updated, so implicitly call
pushListingsSoon() from here. That method doesn't require any particular queue or holding a lock.

(Inspector::RemoteInspector::receivedSetupMessage):
(Inspector::RemoteInspector::receivedDidCloseMessage):
(Inspector::RemoteInspector::receivedConnectionDiedMessage):
Remove calls to updateTargetListing() and pushListingsSoon(), as these happen implicitly
and asynchronously on the target's queue when the connection to target is opened or closed.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (213227 => 213228)


--- trunk/Source/_javascript_Core/ChangeLog	2017-03-01 17:49:59 UTC (rev 213227)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-03-01 18:03:53 UTC (rev 213228)
@@ -1,3 +1,40 @@
+2017-02-28  Brian Burg  <[email protected]>
+
+        REGRESSION(r211344): Remote Inspector: listingForAutomationTarget() is called off-main-thread, causing assertions
+        https://bugs.webkit.org/show_bug.cgi?id=168695
+        <rdar://problem/30643899>
+
+        Reviewed by Joseph Pecoraro.
+
+        The aforementioned commit added some new calls to update target listings. This causes RemoteInspector
+        to update some listings underneath an incoming setup message on the XPC queue, which is not a safe place
+        to gather listing information for RemoteAutomationTargets.
+
+        Update the listing asynchronously since we don't need it immediately. Since this really only happens when
+        the connection to the target is set up and shut down, we can trigger listings to be refreshed from
+        the async block that's called on the target's queue inside RemoteConnectionToTarget::{setup,close}.
+
+        * inspector/remote/RemoteInspector.h:
+        Make updateListingForTarget(unsigned) usable from RemoteConnectionToTarget.
+
+        * inspector/remote/cocoa/RemoteConnectionToTargetCocoa.mm:
+        (Inspector::RemoteConnectionToTarget::setup):
+        (Inspector::RemoteConnectionToTarget::close):
+        Grab the target identifier while the RemoteControllableTarget pointer is still valid,
+        and use it inside the block later after it may have been destructed already. If that happens,
+        then updateTargetListing will bail out because the targetIdentifier cannot be found in the mapping.
+
+        * inspector/remote/cocoa/RemoteInspectorCocoa.mm:
+        (Inspector::RemoteInspector::updateTargetListing):
+        We need to make sure to request a listing push after the target is updated, so implicitly call
+        pushListingsSoon() from here. That method doesn't require any particular queue or holding a lock.
+
+        (Inspector::RemoteInspector::receivedSetupMessage):
+        (Inspector::RemoteInspector::receivedDidCloseMessage):
+        (Inspector::RemoteInspector::receivedConnectionDiedMessage):
+        Remove calls to updateTargetListing() and pushListingsSoon(), as these happen implicitly
+        and asynchronously on the target's queue when the connection to target is opened or closed.
+
 2017-03-01  Tomas Popela  <[email protected]>
 
         Leak under Options::setOptions

Modified: trunk/Source/_javascript_Core/inspector/remote/RemoteInspector.h (213227 => 213228)


--- trunk/Source/_javascript_Core/inspector/remote/RemoteInspector.h	2017-03-01 17:49:59 UTC (rev 213227)
+++ trunk/Source/_javascript_Core/inspector/remote/RemoteInspector.h	2017-03-01 18:03:53 UTC (rev 213228)
@@ -94,6 +94,8 @@
     RetainPtr<CFDataRef> parentProcessAuditData() const { return m_parentProcessAuditData; }
     void setParentProcessInformation(pid_t, RetainPtr<CFDataRef> auditData);
     void setParentProcessInfomationIsDelayed();
+
+    void updateTargetListing(unsigned targetIdentifier);
 #endif
 
 private:
@@ -115,7 +117,6 @@
     void pushListingsNow();
     void pushListingsSoon();
 
-    void updateTargetListing(unsigned targetIdentifier);
     void updateTargetListing(const RemoteControllableTarget&);
 
     void updateHasActiveDebugSession();

Modified: trunk/Source/_javascript_Core/inspector/remote/cocoa/RemoteConnectionToTargetCocoa.mm (213227 => 213228)


--- trunk/Source/_javascript_Core/inspector/remote/cocoa/RemoteConnectionToTargetCocoa.mm	2017-03-01 17:49:59 UTC (rev 213227)
+++ trunk/Source/_javascript_Core/inspector/remote/cocoa/RemoteConnectionToTargetCocoa.mm	2017-03-01 18:03:53 UTC (rev 213228)
@@ -159,12 +159,15 @@
     if (!m_target)
         return false;
 
+    unsigned targetIdentifier = this->targetIdentifier().value_or(0);
+    
     ref();
     dispatchAsyncOnTarget(^{
         {
             std::lock_guard<Lock> lock(m_targetMutex);
+
             if (!m_target || !m_target->remoteControlAllowed()) {
-                RemoteInspector::singleton().setupFailed(targetIdentifier().value_or(0));
+                RemoteInspector::singleton().setupFailed(targetIdentifier);
                 m_target = nullptr;
             } else if (is<RemoteInspectionTarget>(m_target)) {
                 auto castedTarget = downcast<RemoteInspectionTarget>(m_target);
@@ -173,10 +176,14 @@
 
                 if (automaticallyPause)
                     castedTarget->pause();
+
+                RemoteInspector::singleton().updateTargetListing(targetIdentifier);
             } else if (is<RemoteAutomationTarget>(m_target)) {
                 auto castedTarget = downcast<RemoteAutomationTarget>(m_target);
                 castedTarget->connect(this);
                 m_connected = true;
+
+                RemoteInspector::singleton().updateTargetListing(targetIdentifier);
             }
         }
         deref();
@@ -194,16 +201,19 @@
 
 void RemoteConnectionToTarget::close()
 {
+    unsigned targetIdentifier = m_target ? m_target->targetIdentifier() : 0;
+    
     ref();
     dispatchAsyncOnTarget(^{
         {
             std::lock_guard<Lock> lock(m_targetMutex);
-
             if (m_target) {
                 if (m_connected)
                     m_target->disconnect(this);
 
                 m_target = nullptr;
+                
+                RemoteInspector::singleton().updateTargetListing(targetIdentifier);
             }
         }
         deref();

Modified: trunk/Source/_javascript_Core/inspector/remote/cocoa/RemoteInspectorCocoa.mm (213227 => 213228)


--- trunk/Source/_javascript_Core/inspector/remote/cocoa/RemoteInspectorCocoa.mm	2017-03-01 17:49:59 UTC (rev 213227)
+++ trunk/Source/_javascript_Core/inspector/remote/cocoa/RemoteInspectorCocoa.mm	2017-03-01 18:03:53 UTC (rev 213228)
@@ -463,6 +463,8 @@
         return;
 
     m_targetListingMap.set(target.targetIdentifier(), targetListing);
+
+    pushListingsSoon();
 }
 
 #pragma mark - Received XPC Messages
@@ -511,8 +513,6 @@
         ASSERT_NOT_REACHED();
 
     updateHasActiveDebugSession();
-    updateTargetListing(*target);
-    pushListingsSoon();
 }
 
 void RemoteInspector::receivedDataMessage(NSDictionary *userInfo)
@@ -551,8 +551,6 @@
     m_targetConnectionMap.remove(targetIdentifier);
 
     updateHasActiveDebugSession();
-    updateTargetListing(targetIdentifier);
-    pushListingsSoon();
 }
 
 void RemoteInspector::receivedGetListingMessage(NSDictionary *)
@@ -627,13 +625,10 @@
         return;
 
     auto connection = it->value;
-    unsigned targetIdentifier = connection->targetIdentifier().value_or(0);
     connection->close();
     m_targetConnectionMap.remove(it);
 
     updateHasActiveDebugSession();
-    updateTargetListing(targetIdentifier);
-    pushListingsSoon();
 }
 
 void RemoteInspector::receivedAutomaticInspectionConfigurationMessage(NSDictionary *userInfo)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to