-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the bug
The doc string for the LeaderElector's run() method state:
stopLeadingHook called when a LeaderElector client stops leading
However, stopLeadingHook is called both when the client stops leading and when an exception causes the client to exit the acquire loop. In our particular case, the thread executing the acquire loop experienced an InterruptedException which caused this. I think either the docs should be updated to reflect that the hook is called in such cases or the code should be updated to only run the hook when leadership was actually acquired.
From the caller's perspective, I think the latter probably makes more sense. I'd be happy to submit a PR.
Client Version
Present on current tip of master, a86df3a753af9c616f40c18b37ac6ef86921ece9
Kubernetes Version
1.26
Java Version
Java 17
To Reproduce
Steps to reproduce the behavior:
- Pass any
stopLeadingHookto the LeaderElector'srun()method. - Cause the acquire loop to throw an exception.
- Observe the stop leading hook being executed.
Expected behavior
Based on the doc string of the method, I expected the 'stopLeadingHook' to only be executed in cases where the client had actually acquired leadership and its leadership ended.
Server (please complete the following information):
- OS: Linux
- Environment: EC2 VM
- Cloud: AWS