allthingssecurity commented on code in PR #27311:
URL: https://github.com/apache/camel/pull/27311#discussion_r4172036711


##########
components/camel-consul/src/main/java/org/apache/camel/component/consul/cluster/ConsulClusterView.java:
##########
@@ -269,16 +329,29 @@ public void onComplete(ConsulResponse<Optional<Value>> 
consulResponse) {
         public void onFailure(Throwable throwable) {
             LOGGER.debug("{}", throwable.getMessage(), throwable);
 
-            if (sessionId.get() != null) {
-                keyValueClient.releaseLock(configuration.getRootPath(), 
sessionId.get());
+            // the leadership cannot be confirmed: give it up, and release the 
lock if Consul can still be reached
+            localMember.setMaster(false);
+
+            String sid = sessionId.get();
+            if (sid != null) {
+                try {
+                    keyValueClient.releaseLock(path, sid);
+                } catch (Exception e) {
+                    LOGGER.debug("Failed to release lock on path '{}' with id 
'{}': {}", path, sid, e.getMessage(), e);
+                }
             }

Review Comment:
   Done. The release is removed. `onFailure` now only calls `setMaster(false)` 
and schedules the re-watch, and the comment explains why the lock is kept. A 
node that really is cut off loses its session, and with it the lock, through 
the TTL and lock-delay. Covered by `keepsTheLockAfterAFailedQuery`.
   
   _Claude Code on behalf of allthingssecurity_
   



##########
components/camel-consul/src/main/java/org/apache/camel/component/consul/cluster/ConsulClusterView.java:
##########
@@ -95,11 +99,11 @@ protected void doStart() throws Exception {
             client = configuration.createConsulClient(getCamelContext());
             sessionClient = client.sessionClient();
             keyValueClient = client.keyValueClient();
+            // to watch again after a failed query
+            executorService = 
getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(this,

Review Comment:
   Done. The executor is created only after `createSession()` succeeds. If 
`acquireLock()`/`watch()` throws afterwards, it is shut down and the exception 
rethrown. `doesNotLeaveAnExecutorBehindWhenTheSessionCannotBeCreated` covers 
the failed `createSession()` case.
   
   _Claude Code on behalf of allthingssecurity_
   



-- 
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