Skip to content

Commit 0730b40

Browse files
committed
fix: non-hanging WS subscription async loop handling
1 parent 91430ef commit 0730b40

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sdk/src/accounts/webSocketAccountSubscriberV2.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
9393

9494
private async handleNotificationLoop(subscription: AsyncIterable<any>) {
9595
for await (const notification of subscription) {
96+
// If we're currently polling and receive a WebSocket event, stop polling
97+
if (this.pollingTimeoutId) {
98+
if (this.resubOpts?.logResubMessages) {
99+
console.log(
100+
`[${this.logAccountName}] Received WebSocket event while polling, stopping polling`
101+
);
102+
}
103+
this.stopPolling();
104+
}
105+
96106
if (this.resubOpts?.resubTimeoutMs) {
97107
this.receivingData = true;
98108
clearTimeout(this.timeoutId);

0 commit comments

Comments
 (0)