@@ -596,6 +596,26 @@ export function createChannelManager(opts: ChannelManagerOptions): ChannelManage
|
596 | 596 | if (manuallyStopped.has(rKey)) { |
597 | 597 | return; |
598 | 598 | } |
| 599 | +if (recoveryStopTimedOut.has(rKey)) { |
| 600 | +recoveryStopTimedOut.delete(rKey); |
| 601 | +restartAttempts.delete(rKey); |
| 602 | +log.info?.(`[${id}] restarting after timed-out channel stop completed`); |
| 603 | +setRuntime(channelId, id, { |
| 604 | +accountId: id, |
| 605 | +restartPending: true, |
| 606 | +reconnectAttempts: 0, |
| 607 | +}); |
| 608 | +if (store.tasks.get(id) === trackedPromise) { |
| 609 | +store.tasks.delete(id); |
| 610 | +} |
| 611 | +if (store.aborts.get(id) === abort) { |
| 612 | +store.aborts.delete(id); |
| 613 | +} |
| 614 | +await startChannelInternal(channelId, id, { |
| 615 | +preserveManualStop: true, |
| 616 | +}); |
| 617 | +return; |
| 618 | +} |
599 | 619 | const attempt = (restartAttempts.get(rKey) ?? 0) + 1; |
600 | 620 | restartAttempts.set(rKey, attempt); |
601 | 621 | if (attempt > MAX_RESTART_ATTEMPTS) { |
@@ -616,24 +636,15 @@ export function createChannelManager(opts: ChannelManagerOptions): ChannelManage
|
616 | 636 | restartPending: true, |
617 | 637 | reconnectAttempts: attempt, |
618 | 638 | }); |
619 | | -const recoveryRestartSleepAbort = recoveryStopTimedOut.has(rKey) |
620 | | - ? new AbortController() |
621 | | - : undefined; |
622 | | -if (recoveryRestartSleepAbort) { |
623 | | -store.aborts.set(id, recoveryRestartSleepAbort); |
624 | | -} |
625 | 639 | try { |
626 | | -const restartSleepAbort = recoveryRestartSleepAbort?.signal ?? abort.signal; |
627 | | -await sleepWithAbort(delayMs, restartSleepAbort); |
| 640 | +await sleepWithAbort(delayMs, abort.signal); |
628 | 641 | if (manuallyStopped.has(rKey)) { |
629 | | -recoveryStopTimedOut.delete(rKey); |
630 | 642 | return; |
631 | 643 | } |
632 | | -recoveryStopTimedOut.delete(rKey); |
633 | 644 | if (store.tasks.get(id) === trackedPromise) { |
634 | 645 | store.tasks.delete(id); |
635 | 646 | } |
636 | | -if (store.aborts.get(id) === (recoveryRestartSleepAbort ?? abort)) { |
| 647 | +if (store.aborts.get(id) === abort) { |
637 | 648 | store.aborts.delete(id); |
638 | 649 | } |
639 | 650 | await startChannelInternal(channelId, id, { |
@@ -642,13 +653,6 @@ export function createChannelManager(opts: ChannelManagerOptions): ChannelManage
|
642 | 653 | }); |
643 | 654 | } catch { |
644 | 655 | // abort or startup failure — next crash will retry |
645 | | -} finally { |
646 | | -if (recoveryRestartSleepAbort) { |
647 | | -recoveryStopTimedOut.delete(rKey); |
648 | | -if (store.aborts.get(id) === recoveryRestartSleepAbort) { |
649 | | -store.aborts.delete(id); |
650 | | -} |
651 | | -} |
652 | 656 | } |
653 | 657 | }) |
654 | 658 | .finally(() => { |
|