Skip to content

LeaderElector fails to acquire expired lease on initial run due to missing expiration check #4913

Description

@marbon87

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

  • OS: wsl2 with kind

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions