Skip to content

Commit ae08e08

Browse files
authored
fix: Stream retry failure due to previous open connection. (#409)
This should fix #405 or at least provide more logging to debug the issue further if it persists.
1 parent 6601480 commit ae08e08

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/sdk/react-native/src/fromExternal/react-native-sse/EventSource.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('EventSource', () => {
1818
.mockImplementationOnce(() => 0.999);
1919

2020
eventSource = new EventSource<EventName>(uri, { logger });
21+
eventSource.onclose = jest.fn();
2122
eventSource.open = jest.fn();
2223
eventSource.onretrying = jest.fn();
2324
});
@@ -72,7 +73,8 @@ describe('EventSource', () => {
7273

7374
expect(logger.debug).toHaveBeenCalledWith(expect.stringMatching(/new connection in 0 ms/i));
7475
expect(eventSource.onretrying).toHaveBeenCalledWith({ type: 'retry', delayMillis: 0 });
75-
expect(eventSource.open).toHaveBeenCalledTimes(2);
76+
expect(eventSource.open).toHaveBeenCalledTimes(1);
77+
expect(eventSource.onclose).toHaveBeenCalledTimes(1);
7678
});
7779

7880
test('tryConnect with delay', () => {
@@ -85,6 +87,7 @@ describe('EventSource', () => {
8587
expect.stringMatching(/new connection in 556 ms/i),
8688
);
8789
expect(eventSource.onretrying).toHaveBeenCalledWith({ type: 'retry', delayMillis: 556 });
88-
expect(eventSource.open).toHaveBeenCalledTimes(2);
90+
expect(eventSource.open).toHaveBeenCalledTimes(1);
91+
expect(eventSource.onclose).toHaveBeenCalledTimes(1);
8992
});
9093
});

packages/sdk/react-native/src/fromExternal/react-native-sse/EventSource.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export default class EventSource<E extends string = never> {
9393
this.logger?.debug(`[EventSource] Will open new connection in ${delay} ms.`);
9494
this.dispatch('retry', { type: 'retry', delayMillis: delay });
9595
this.pollTimer = setTimeout(() => {
96+
this.close();
9697
this.open();
9798
}, delay);
9899
}
@@ -315,6 +316,7 @@ export default class EventSource<E extends string = never> {
315316
this.onclose();
316317
break;
317318
case 'error':
319+
this.logger?.debug(`[EventSource][dispatch][ERROR]: ${JSON.stringify(data)}`);
318320
this.onerror(data);
319321
break;
320322
case 'retry':

0 commit comments

Comments
 (0)