Describe the bug
There is a flaw in the LeaderElector's tryAcquireOrRenew() logic when handling an existing but expired lease.
On the initial run the application fails to explicitly check if the current observed time has surpassed renewTime + leaseDurationSeconds. Instead, it skips acquiring the lease even when the lock is already free/expired.
Client Version
24.0.0
Kubernetes Version
1.37.0
Java Version
Java 25
To Reproduce
Start the test LeaderElectorExampleTest.java from https://github.com/marbon87/kubernetes-client-java
Expected behavior
LeaderElector should acquire a lock on first try without waiting if renewTime + leaseDurationSeconds is in the past.
Possible solution could be
|
// if(oldLeaderElectionRecord.getRenewTime()!=null) { |
|
// this.observedTimeMilliSeconds = oldLeaderElectionRecord.getRenewTime() |
|
// .toInstant().toEpochMilli(); |
|
// } else { |
|
// this.observedTimeMilliSeconds = System.currentTimeMillis(); |
|
// } |
Server (please complete the following information):
Describe the bug
There is a flaw in the LeaderElector's tryAcquireOrRenew() logic when handling an existing but expired lease.
On the initial run the application fails to explicitly check if the current observed time has surpassed renewTime + leaseDurationSeconds. Instead, it skips acquiring the lease even when the lock is already free/expired.
Client Version
24.0.0
Kubernetes Version
1.37.0
Java Version
Java 25
To Reproduce
Start the test LeaderElectorExampleTest.java from https://github.com/marbon87/kubernetes-client-java
Expected behavior
LeaderElector should acquire a lock on first try without waiting if renewTime + leaseDurationSeconds is in the past.
Possible solution could be
java/extended/src/main/java/io/kubernetes/client/extended/leaderelection/LeaderElector.java
Lines 338 to 343 in 40d0967
Server (please complete the following information):