Skip to content

Commit 55c45ab

Browse files
committed
fix(supervisor): prevent escalating duplicate reconnections in failedPodHandler
1 parent d90da7a commit 55c45ab

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

apps/supervisor/src/services/failedPodHandler.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class FailedPodHandler {
2525

2626
private readonly informer: Informer<V1Pod>;
2727
private readonly reconnectIntervalMs: number;
28+
private reconnecting = false;
2829

2930
// Metrics
3031
private readonly register: Registry;
@@ -250,21 +251,41 @@ export class FailedPodHandler {
250251
}
251252

252253
private makeOnError(informerName: string) {
253-
return () => this.onError(informerName);
254+
return (err?: unknown) => this.onError(informerName, err);
254255
}
255256

256-
private async onError(informerName: string) {
257+
private async onError(informerName: string, err?: unknown) {
257258
if (!this.isRunning) {
258259
this.logger.warn("onError: informer not running");
259260
return;
260261
}
261262

262-
this.logger.error("error event fired", { informerName });
263-
this.informerEventsTotal.inc({ namespace: this.namespace, verb: "error" });
263+
// Guard against multiple simultaneous reconnections
264+
if (this.reconnecting) {
265+
this.logger.debug("onError: reconnection already in progress, skipping", {
266+
informerName,
267+
});
268+
return;
269+
}
264270

265-
// Reconnect on errors
266-
await setTimeout(this.reconnectIntervalMs);
267-
await this.informer.start();
271+
this.reconnecting = true;
272+
273+
try {
274+
const error = err instanceof Error ? err : undefined;
275+
this.logger.error("error event fired", {
276+
informerName,
277+
error: error?.message,
278+
errorType: error?.name,
279+
errorStack: error?.stack,
280+
});
281+
this.informerEventsTotal.inc({ namespace: this.namespace, verb: "error" });
282+
283+
// Reconnect on errors
284+
await setTimeout(this.reconnectIntervalMs);
285+
await this.informer.start();
286+
} finally {
287+
this.reconnecting = false;
288+
}
268289
}
269290

270291
private makeOnConnect(informerName: string) {

0 commit comments

Comments
 (0)