fix: recover channel after stop timeout in health monitor

When a channel stop times out (e.g. during a Telegram API outage),
the channel enters recoveryStopTimedOut state. The health monitor's
subsequent start call would set restartPending and return without
actually starting the channel.

If the stuck stop never completes, the channel stays in limbo forever
with the health monitor retrying every cycle but never recovering.

Fix: when the health monitor retries recovery (recoveryStartRequested
already set), clean up the stuck task state and allow the channel to
start normally.

Closes #94008
This commit is contained in:
sheyanmin
2026-06-17 16:10:13 +08:00
committed by Ayaan Zaidi
parent 210ea659f7
commit 8b4be2fdd4

View File

@@ -456,8 +456,25 @@ export function createChannelManager(opts: ChannelManagerOptions): ChannelManage
if (manuallyStopped.has(rKey)) {
return;
}
recoveryStartRequested.add(rKey);
setRuntime(channelId, id, { accountId: id, restartPending: true });
// When a previous stop timed out and the health monitor is
// requesting recovery again, clean up the stuck task so the
// channel can actually restart instead of staying in limbo.
if (recoveryStartRequested.has(rKey)) {
recoveryStopTimedOut.delete(rKey);
recoveryStartRequested.delete(rKey);
restartAttempts.delete(rKey);
store.aborts.delete(id);
store.tasks.delete(id);
setRuntime(channelId, id, {
accountId: id,
restartPending: false,
reconnectAttempts: 0,
});
} else {
recoveryStartRequested.add(rKey);
setRuntime(channelId, id, { accountId: id, restartPending: true });
return;
}
}
return;
}