Skip to content

Commit 841cb12

Browse files
committed
fix(twitch): cancel auth retry disconnects
1 parent 08159d8 commit 841cb12

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

extensions/twitch/src/twitch-client.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ describe("TwitchClientManager", () => {
231231
await expect(connection).resolves.toBeTruthy();
232232
});
233233

234+
it("rejects pending auth retry connections on manual disconnect", async () => {
235+
mockConnect.mockImplementationOnce(() => {});
236+
237+
const connection = manager.getClient(testAccount);
238+
await Promise.resolve();
239+
authFailureHandlers[0]?.("bad token", 1);
240+
disconnectHandlers[0]?.(true);
241+
242+
await expect(connection).rejects.toThrow("Twitch connection cancelled");
243+
});
244+
234245
it("does not cache pending connections after disconnectAll", async () => {
235246
mockConnect.mockImplementationOnce(() => {});
236247

extensions/twitch/src/twitch-client.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,21 @@ export class TwitchClientManager {
231231
`Twitch authentication failed for ${account.username}; waiting for retry, disconnect, or timeout: ${text}`,
232232
);
233233
}),
234-
client.onDisconnect((_manual, reason) => {
235-
if (authRetryPending) {
234+
client.onDisconnect((manual, reason) => {
235+
if (authRetryPending && !manual) {
236236
this.logger.debug?.(
237237
`Twitch disconnected during auth retry for ${account.username}: ${formatErrorMessage(reason)}`,
238238
);
239239
return;
240240
}
241-
finish(reason ?? new Error(`Twitch disconnected before ready for ${account.username}`));
241+
finish(
242+
reason ??
243+
new Error(
244+
manual
245+
? `Twitch connection cancelled for ${account.username}`
246+
: `Twitch disconnected before ready for ${account.username}`,
247+
),
248+
);
242249
}),
243250
);
244251
timeout = setTimeout(

0 commit comments

Comments
 (0)