Skip to content

Commit 964b7e4

Browse files
committed
fix(webapp): reschedule reconnect when subscribe() returns stopped
LogicalReplicationClient.subscribe() can resolve without throwing or emitting an "error" event when leader-lock acquisition fails — it just calls this.stop() and returns. The reconnect callback now checks isStopped after subscribe() and throws so the recovery handler can schedule the next attempt instead of silently giving up.
1 parent 1e081e1 commit 964b7e4

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

apps/webapp/app/services/runsReplicationService.server.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ export class RunsReplicationService {
264264
logger: this.logger,
265265
reconnect: async () => {
266266
await this._replicationClient.subscribe(this._latestCommitEndLsn ?? undefined);
267+
if (this._replicationClient.isStopped) {
268+
// subscribe() can resolve without throwing or emitting an "error"
269+
// event when leader-lock acquisition fails (see LogicalReplication-
270+
// Client.subscribe leader-election branch). Throw here so the
271+
// recovery handler reschedules the next attempt.
272+
throw new Error("Replication client stopped after subscribe()");
273+
}
267274
},
268275
isShuttingDown: () => this._isShuttingDown || this._isShutDownComplete,
269276
});

apps/webapp/app/services/sessionsReplicationService.server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ export class SessionsReplicationService {
245245
logger: this.logger,
246246
reconnect: async () => {
247247
await this._replicationClient.subscribe(this._latestCommitEndLsn ?? undefined);
248+
if (this._replicationClient.isStopped) {
249+
// See RunsReplicationService for the rationale: subscribe() can
250+
// resolve without throwing when leader-lock acquisition fails.
251+
throw new Error("Replication client stopped after subscribe()");
252+
}
248253
},
249254
isShuttingDown: () => this._isShuttingDown || this._isShutDownComplete,
250255
});

0 commit comments

Comments
 (0)