fix(analytics): guard polling start so concurrent callers don't leak executors (SDK-81)#91
Open
tylerjroach wants to merge 2 commits into
Open
fix(analytics): guard polling start so concurrent callers don't leak executors (SDK-81)#91tylerjroach wants to merge 2 commits into
tylerjroach wants to merge 2 commits into
Conversation
…utors startPollingForDefinitions had no lock around the pollingExecutor create-and-assign. Two concurrent callers would each allocate a fresh ScheduledExecutorService and the earlier one's worker thread + queue would leak (still alive, still scheduled to poll, no way to shut it down because the field had been overwritten). Guard the executor lifecycle with a private lock and bail early if a poller is already scheduled. Snapshot the executor under the lock in stop, then run the (potentially blocking) shutdown / awaitTermination outside the lock so a long-running shutdown can't block a concurrent start for 5s. Linear: SDK-85 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4 tasks
Contributor
Author
Copy-paste typo — the PR, commit, and Linear link all reference SDK-81; only the test region comment said SDK-85.
Contributor
Author
|
Pushed |
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.
Summary
startPollingForDefinitionshad no lock around the create-and-assign ofpollingExecutor. Two concurrent callers would each allocate a freshScheduledExecutorService, the field would point at the second, and the first executor's worker thread + scheduled task would silently leak (still alive, still polling, no longer reachable for shutdown).Add a private
pollingLockguarding the executor's lifecycle:startPollingForDefinitions: under the lock, bail early ifpollingExecutor != null(idempotent), otherwise create + schedule.stopPollingForDefinitions: snapshot the executor under the lock and clear the field, then runshutdown/awaitTerminationoutside the lock so a long shutdown can't block a concurrent start for 5s.Context
Linear: SDK-81. Same audit-driven cross-SDK push; Java is one of three affected (Java, Ruby, Node). Python uses a
not self._polling_taskcheck that's safe because both async and sync paths share it under the GIL; Go usesCompareAndSwap.Test plan
LocalFlagsProviderTesttests pass (mvn test)testConcurrentStartPollingDoesNotLeakExecutorsspins up 8 contender threads behind aCountDownLatchstart gate. Counts JVM threads namedmixpanel-flags-pollerbefore and after; asserts exactly one new poller exists, then assertsstopcleans it up. Before this fix the count would be 8.🤖 Generated with Claude Code