Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo committed Jan 8, 2025
1 parent 885c7df commit b49cc8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/abacus-ts/websocket/lib/indexerWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class IndexerWebsocket {
});
};

// if we get a "coud not fetch data" error, we retry once as long as this channel is not on cooldown
// if we get a "could not fetch data" error, we retry once as long as this channel is not on cooldown
// TODO: when backend adds the channel and id to the error message, use that to retry only one subscription
// TODO: remove this entirely when backend is more reliable
private _handleErrorReceived = (message: string) => {
Expand All @@ -154,8 +154,8 @@ export class IndexerWebsocket {
.at(-2);
if (maybeChannel != null && maybeChannel.startsWith('v4_')) {
const lastRefresh = this.lastRetryTimeMsByChannel[maybeChannel] ?? 0;
if (new Date().valueOf() - lastRefresh > CHANNEL_RETRY_COOLDOWN_MS) {
this.lastRetryTimeMsByChannel[maybeChannel] = new Date().valueOf();
if (Date.now() - lastRefresh > CHANNEL_RETRY_COOLDOWN_MS) {
this.lastRetryTimeMsByChannel[maybeChannel] = Date.now();
this._refreshChannelSubs(maybeChannel);
logAbacusTsError(
'IndexerWebsocket',
Expand Down
11 changes: 9 additions & 2 deletions src/abacus-ts/websocket/lib/reconnectingWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,15 @@ class WebSocketConnection {
};

this.ws.onclose = (close) => {
// 1000 is expected and 1001 is for browser navigating away, 1005 is on purpose, below that are unused
if (close.code > 1001 && close.code !== 1005) {
const allowedCodes = new Set([
// normal
1000,
// going away (nav or graceful server shutdown)
1001,
// normal but no code
1005,
]);
if (!allowedCodes.has(close.code)) {
logAbacusTsError('WebSocketConnection', `socket ${this.id} closed abnormally`, {
code: close.code,
reason: close.reason,
Expand Down

0 comments on commit b49cc8d

Please sign in to comment.