Repository navigation
[Ready] SOLR-6213: Cap failed election watch retries in LeaderElector - #5209
Draft
nick-boss-tech wants to merge 3 commits into
Draft
nick-boss-tech wants to merge 3 commits into
nick-boss-tech wants to merge 3 commits into
Conversation
A KeeperException while setting the watch on the previous election node called checkIfIamLeader again without limit, so a persistent failure such as NoAuth ended in a StackOverflowError. After three failed attempts the exception is now thrown to the caller.
nick-boss-tech
marked this pull request as ready for review
October 23, 2026 19:52
nick-boss-tech
marked this pull request as draft
October 28, 2026 04:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖 (reviewed by Nick Shanin)
Ready for review, but held as a draft due to the project's open-PR cap; I'll mark it open on request.
https://issues.apache.org/jira/browse/SOLR-6213
What happens today
A failed election watch is retried until the stack overflows.
When a replica is not the leader,
LeaderElector.checkIfIamLeadersets a watch on the election node just ahead of it. If setting that watch fails with aKeeperExceptionother thanNoNode, the method calls itself again at once (line 161 on the base). Nothing limits the repeats and nothing waits between them. A failure that does not go away, such as theNoAutherror in the 2025 report on the ticket, ends in aStackOverflowError.What this change does
The retry stops after three attempts, and the third failure is thrown to the caller.
A join then sees the real
KeeperExceptionand the log shows it. TheNoNodecase, where the node ahead disappeared, still checks again at once, because the next check finds a new node to watch. The limit isLeaderElector.MAX_WATCH_FAILURES.Proof
The new test fails on the base code with a StackOverflowError and passes at this head.
LeaderElectionTest.testRepeatedWatchFailureIsRaisedInsteadOfRetriedForevermakes everygetDatacall on the second elector's ZooKeeper client fail withNoAuth. With the new test run against the base code, it fails withStackOverflowError. At heada55a45e8babit passes, and the test verifies theNoAuthexception reaches the caller after exactly threegetDatacalls.LeaderElectionTestas a whole passes at this head: 6 tests, 0 failures (seed 6213, run 2026-10-23). Tidy, the Error Prone compile, and:solr:core:check -x testalso pass at this head.A choice to check
Two routes were available: stop after three attempts and throw, or keep retrying with a growing pause.
Context: the retry only runs inside a watcher callback or a join, so there is no thread of its own to wait on. A persistent failure such as a missing permission does not clear in the milliseconds a short retry spans.
The deciding questions, in order: Can a retry fix the error? Only a short ZooKeeper hiccup, and three attempts cover that. Is a thread available to wait on? No. Which is worse, an exception that reaches the log or an endless loop? The loop.
Recommendation: stop after three attempts and throw (the route implemented here). Is a limit of three the right number?
Limits
The cap covers this watch retry only.
After the third failure the replica has no watch until it joins the election again, for example after a session expiry. Before this change that replica also ended without a watch, through the overflow. The nested rejoin path in
ShardLeaderElectionContextis a different loop and is in a separate change.retryElectionalso re-joins without a limit; it creates a new election node on each pass and was left alone.Changelog: changelog/unreleased/SOLR-6213-watch-retry.yml
AI-generated description. Nick Shanin directed the work and takes responsibility for this contribution.