fix(analytics): keep polling alive when fetch throws a Throwable (SDK-86)#93
Open
tylerjroach wants to merge 1 commit into
Open
fix(analytics): keep polling alive when fetch throws a Throwable (SDK-86)#93tylerjroach wants to merge 1 commit into
tylerjroach wants to merge 1 commit into
Conversation
ScheduledExecutorService#scheduleAtFixedRate permanently cancels future executions if the runnable throws an uncaught Throwable. fetchDefinitions only catches Exception, so an Error (OOM, StackOverflowError, LinkageError, etc.) escaping would silently kill flag-definitions polling for the JVM's lifetime. Wrap the scheduled runnable in a defensive try/catch(Throwable). fetchDefinitions keeps its Exception handling unchanged; the wrapper exists purely to swallow + log JVM-level escapes so the schedule keeps firing. Linear: SDK-86 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Confidence Score: 5/5Safe to merge — the change is a single narrow defensive wrapper that leaves all existing logic untouched. The change is minimal and well-targeted: one extra lambda wrapping one method call, with a new test that directly validates the scheduling-survives-Error behavior. No existing paths are altered. No files require special attention.
|
| Filename | Overview |
|---|---|
| src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java | Wraps the scheduled fetchDefinitions() call in a try-catch (Throwable) to prevent ScheduledExecutorService from silently cancelling the polling task on JVM-level Errors; rest of the file unchanged. |
| src/test/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProviderTest.java | Adds testPollingSurvivesThrowableFromFetch which arms an Error on the second httpGet call and asserts polling continues (callCount >= 3) after 2.5s; correct and well-structured. |
Reviews (1): Last reviewed commit: "fix(analytics): keep polling alive when ..." | Re-trigger Greptile
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
ScheduledExecutorService#scheduleAtFixedRatepermanently cancels future executions if the runnable throws an uncaughtThrowable.fetchDefinitions()only catchesException, so anError(OutOfMemoryError,StackOverflowError,LinkageError, etc.) escaping would silently kill flag-definitions polling for the JVM's lifetime — and the thread factory has noUncaughtExceptionHandlerto even surface it.Wrap the scheduled runnable in a defensive
try { fetchDefinitions(); } catch (Throwable t) { logger.log(SEVERE, ...) }.fetchDefinitions()keeps itsExceptionhandling unchanged; the wrapper exists purely to swallow + log JVM-level escapes so the schedule keeps firing.Context
Linear: SDK-86. Practical scope is narrow (JVM-level errors only) but the defense is one-line.
Test plan
testPollingSurvivesThrowableFromFetcharms anErrorto escape the secondhttpGetcall, then asserts the polling task continues to fire (callCount >= 3after 2.5s with a 1s interval). Before the fix the scheduler would have cancelled the task on theErrorandcallCountwould have stopped at 2.