Browse Source

HPCC-14190 Avoid possible deadlock during node subscription removal

If whilst a node subscription subscriber is being notified, it is
asynchronously removed, it could cause deadlock.
Avoid by ensuring have data lock before trying to remove.

Signed-off-by: Jake Smith <jake.smith@lexisnexis.com>
Jake Smith 9 năm trước cách đây
mục cha
commit
184192ea29
1 tập tin đã thay đổi với 5 bổ sung2 xóa
  1. 5 2
      dali/base/dasds.cpp

+ 5 - 2
dali/base/dasds.cpp

@@ -2796,6 +2796,11 @@ public:
     }
     }
     virtual void remove(SubscriptionId id)
     virtual void remove(SubscriptionId id)
     {
     {
+        /* important to ensure have exclusive data lock on removal, ahead of subscriber lock
+         * as can get notifications whilst holding data lock, e.g. notifyDelete on node destruction.
+         */
+        CHECKEDDALIREADLOCKBLOCK(owner.dataRWLock, readWriteTimeout);
+        CHECKEDCRITICALBLOCK(owner.treeRegCrit, fakeCritTimeout);
         CriticalBlock b(lock);
         CriticalBlock b(lock);
         /* calls back out to owner to protect root/treereg.
         /* calls back out to owner to protect root/treereg.
          * It calls back into removeSubscriberAssociation.
          * It calls back into removeSubscriberAssociation.
@@ -8630,8 +8635,6 @@ void CCovenSDSManager::addNodeSubscriber(ISubscription *sub, SubscriptionId id)
 
 
 void CCovenSDSManager::removeNodeSubscriber(SubscriptionId id)
 void CCovenSDSManager::removeNodeSubscriber(SubscriptionId id)
 {
 {
-    CHECKEDDALIREADLOCKBLOCK(dataRWLock, readWriteTimeout);
-    CHECKEDCRITICALBLOCK(treeRegCrit, fakeCritTimeout);
     nodeSubscriptionManager->removeSubscriberAssociation(id);
     nodeSubscriptionManager->removeSubscriberAssociation(id);
 }
 }