Skip to content

Commit d96b46b

Browse files
authored
fix: Improve error handling for FDv2 streaming (#1184)
BEGIN_COMMIT_OVERRIDE fix: Improve error handling for FDv2 streaming fix: Allow 0 status code to be handled by the streaming error filter. END_COMMIT_OVERRIDE <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes reconnection/error classification logic in the streaming data source, which could affect when clients retry vs surface interruptions. Risk is moderate because it impacts core connectivity behavior but is localized and guarded by existing error filters. > > **Overview** > Improves streaming error handling so *any numeric* `err.status` (including `0`) is routed through the EventSource `errorFilter` rather than being treated as a missing-status/network error. > > Reduces noise and false failures by (1) not warning when FDv2 `'error'` events arrive without a body, and (2) only queuing a network interruption on `es.onerror` when no numeric HTTP status is present (letting the filter handle status-bearing errors). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 28ac8cf. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent cd4b119 commit d96b46b

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

packages/sdk/browser/src/platform/DefaultBrowserEventSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default class DefaultBrowserEventSource implements LDEventSource {
9797
// The event source may not produce a status. But the LaunchDarkly
9898
// polyfill can. If we can get the status, then we should stop retrying
9999
// on certain error codes.
100-
if (err.status && typeof err.status === 'number' && !this._errorFilter(err)) {
100+
if (typeof err.status === 'number' && !this._errorFilter(err)) {
101101
// If we encounter an unrecoverable condition, then we do not want to
102102
// retry anymore.
103103
return;

packages/shared/sdk-client/src/datasource/fdv2/StreamingFDv2Base.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ export function createStreamingBase(config: {
188188
}
189189

190190
if (!event?.data) {
191-
config.logger?.warn(`Event from EventStream missing data for "${eventName}".`);
191+
// Some events (e.g. 'error') may legitimately arrive without a body.
192+
if (eventName !== 'error') {
193+
config.logger?.warn(`Event from EventStream missing data for "${eventName}".`);
194+
}
192195
return;
193196
}
194197

@@ -277,8 +280,18 @@ export function createStreamingBase(config: {
277280
config.logger?.info('Closed LaunchDarkly stream connection');
278281
};
279282

280-
es.onerror = () => {
281-
// Error handling is done by errorFilter.
283+
es.onerror = (err?: HttpErrorResponse) => {
284+
if (stopped) {
285+
return;
286+
}
287+
288+
if (err && typeof err.status === 'number') {
289+
// This condition will be handled by the error filter.
290+
return;
291+
}
292+
resultQueue.put(
293+
interrupted(errorInfoFromNetworkError(err?.message ?? 'IO Error'), fdv1Fallback),
294+
);
282295
};
283296

284297
es.onopen = () => {

0 commit comments

Comments
 (0)