fix(analytics): keep polling alive when fetch throws a Throwable (SDK-86)#93
Open
tylerjroach wants to merge 2 commits into
Open
fix(analytics): keep polling alive when fetch throws a Throwable (SDK-86)#93tylerjroach wants to merge 2 commits into
tylerjroach wants to merge 2 commits 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>
There was a problem hiding this comment.
Using catch (Throwable t) instead of catch (Exception e) here will achieve same?
There was a problem hiding this comment.
@copilot can you check if this comment is valid?
Contributor
There was a problem hiding this comment.
Yes, that's correct and simpler. Changed catch (Exception e) to catch (Throwable t) directly in fetchDefinitions() and removed the wrapper lambda — same protection, less indirection. Commit: refactor: simplify Throwable catch to fetchDefinitions directly.
Co-authored-by: ketanmixpanel <188901560+ketanmixpanel@users.noreply.github.com>
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.