Skip to content

Commit f223cea

Browse files
thomasballingerConvex, Inc.
authored andcommitted
Backoff more for SubscriptionsWorkerFullError (#37750)
GitOrigin-RevId: b736c4a8673bd784ec923e6bcb572cf21eff47df
1 parent 757d358 commit f223cea

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

npm-packages/convex/src/browser/sync/web_socket_manager.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ export class WebSocketManager {
253253
}
254254
this.logger.log(msg);
255255
}
256-
this.scheduleReconnect();
256+
if (event.reason?.includes("SubscriptionsWorkerFullError")) {
257+
this.scheduleReconnect("SubscriptionsWorkerFullError");
258+
} else {
259+
this.scheduleReconnect("unknown");
260+
}
257261
return;
258262
};
259263
}
@@ -320,9 +324,11 @@ export class WebSocketManager {
320324
}, this.serverInactivityThreshold);
321325
}
322326

323-
private scheduleReconnect() {
327+
private scheduleReconnect(
328+
reason: "client" | "unknown" | "SubscriptionsWorkerFullError",
329+
) {
324330
this.socket = { state: "disconnected" };
325-
const backoff = this.nextBackoff();
331+
const backoff = this.nextBackoff(reason);
326332
this.logger.log(`Attempting reconnect in ${backoff}ms`);
327333
setTimeout(() => this.connect(), backoff);
328334
}
@@ -345,7 +351,7 @@ export class WebSocketManager {
345351
this.lastCloseReason = closeReason;
346352
// Close the old socket asynchronously, we'll open a new socket in reconnect.
347353
void this.close();
348-
this.scheduleReconnect();
354+
this.scheduleReconnect("client");
349355
return;
350356
}
351357
default: {
@@ -543,8 +549,12 @@ export class WebSocketManager {
543549
this.logger.logVerbose(message);
544550
}
545551

546-
private nextBackoff(): number {
547-
const baseBackoff = this.initialBackoff * Math.pow(2, this.retries);
552+
private nextBackoff(
553+
reason: "client" | "unknown" | "SubscriptionsWorkerFullError",
554+
): number {
555+
const initialBackoff =
556+
reason === "SubscriptionsWorkerFullError" ? 3000 : this.initialBackoff;
557+
const baseBackoff = initialBackoff * Math.pow(2, this.retries);
548558
this.retries += 1;
549559
const actualBackoff = Math.min(baseBackoff, this.maxBackoff);
550560
const jitter = actualBackoff * (Math.random() - 0.5);

0 commit comments

Comments
 (0)