Skip to content

Commit 62c3119

Browse files
committed
fix(gateway): discard removed thaw targets
1 parent 0786873 commit 62c3119

2 files changed

Lines changed: 58 additions & 6 deletions

File tree

‎src/gateway/channel-thaw-restart.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,17 @@ export async function restartRunningChannelAccounts(
6565
return [...failedTargets, ...targets.slice(index)];
6666
}
6767
try {
68-
const current = manager.getRuntimeSnapshot().channelAccounts[channelId]?.[accountId];
69-
if (current) {
70-
await manager.stopChannel(channelId, accountId, { manual: false });
71-
if (!opts.shouldContinue()) {
72-
return [...failedTargets, target, ...targets.slice(index + 1)];
73-
}
68+
let current = manager.getRuntimeSnapshot().channelAccounts[channelId]?.[accountId];
69+
if (!current) {
70+
continue;
71+
}
72+
await manager.stopChannel(channelId, accountId, { manual: false });
73+
if (!opts.shouldContinue()) {
74+
return [...failedTargets, target, ...targets.slice(index + 1)];
75+
}
76+
current = manager.getRuntimeSnapshot().channelAccounts[channelId]?.[accountId];
77+
if (!current) {
78+
continue;
7479
}
7580
let startOutcome = await manager.startChannelAccountForRecovery(channelId, accountId, {
7681
preserveManualStop: true,

‎src/gateway/server-channels.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,53 @@ describe("server-channels auto restart", () => {
12161216
).toBe(true);
12171217
});
12181218

1219+
it("discards a deferred thaw target removed from the current account list", async () => {
1220+
let accountIds = ["removed"];
1221+
let failStart = false;
1222+
const startAccount = vi.fn(
1223+
async (context: ChannelGatewayContext<TestAccount>) =>
1224+
await new Promise<void>((resolve) => {
1225+
context.abortSignal.addEventListener("abort", () => resolve(), { once: true });
1226+
}),
1227+
);
1228+
installTestRegistry(
1229+
createTestPlugin({
1230+
listAccountIds: () => accountIds,
1231+
isConfigured: async () => {
1232+
if (failStart) {
1233+
throw new Error("start preflight failed");
1234+
}
1235+
return true;
1236+
},
1237+
startAccount,
1238+
}),
1239+
);
1240+
const manager = createManager();
1241+
await manager.startChannels();
1242+
await vi.waitFor(() => expect(startAccount).toHaveBeenCalledOnce());
1243+
1244+
failStart = true;
1245+
const failedTargets = await restartRunningChannelAccounts(manager, {
1246+
shouldContinue: () => true,
1247+
onError: () => {},
1248+
});
1249+
expect(failedTargets).toEqual([{ channelId: "discord", accountId: "removed" }]);
1250+
1251+
accountIds = [];
1252+
failStart = false;
1253+
const errors: string[] = [];
1254+
const second = await restartRunningChannelAccounts(
1255+
manager,
1256+
{ shouldContinue: () => true, onError: (message) => errors.push(message) },
1257+
{ kind: "deferred-retry", targets: failedTargets },
1258+
);
1259+
1260+
expect(second).toEqual([]);
1261+
expect(errors).toEqual([]);
1262+
expect(startAccount).toHaveBeenCalledOnce();
1263+
expect(manager.getRuntimeSnapshot().channelAccounts.discord?.removed).toBeUndefined();
1264+
});
1265+
12191266
it.each(["disabled", "unconfigured"] as const)(
12201267
"does not retain an account that becomes %s during host-thaw recovery",
12211268
async (skipReason) => {

0 commit comments

Comments
 (0)