henrik242 commented on code in PR #26112:
URL: https://github.com/apache/camel/pull/26112#discussion_r3947935962


##########
components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java:
##########
@@ -109,14 +116,19 @@ protected void doStart() throws Exception {
     protected void doStop() throws Exception {
         super.doStop();
 
-        // a start can still be pending, cancel it first so it cannot start 
the delegated consumer
-        // after this consumer has been stopped
-        leadershipTaken = false;
-        cancelLeaderTask(true);
+        leadershipLock.lock();
+        try {
+            // a start can still be pending, cancel it first so it cannot 
start the delegated consumer
+            // after this consumer has been stopped
+            leadershipTaken = false;
+            cancelLeaderTask(true);
+        } finally {
+            leadershipLock.unlock();
+        }
 
-        // note: removeEventListener below needs the cluster view lock while 
this thread holds the lock of
-        // this service, which is the opposite order of an event dispatch. 
Nothing that runs under this lock
-        // may wait for the view, and the listener bails out before locking 
once this consumer is stopping
+        // note: removeEventListener below needs the write lock of the cluster 
view, while an event dispatch
+        // takes the read lock of the view and then leadershipLock. This 
thread must not hold leadershipLock
+        // here, or the two orders deadlock

Review Comment:
   stop() sets status = STOPPING before calling doStop() 
(`BaseService.java:173-176`), so the gate is closed regardless of 
super.doStop(). Adding that would record a cause that isn't real.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to