Skip to content

Commit 93f1e1b

Browse files
committed
fix(irc): stop chunk fanout after disconnect
1 parent d2de917 commit 93f1e1b

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎extensions/irc/src/send.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,49 @@ describe("sendMessageIrc cfg threading", () => {
425425
expect(client.quit).toHaveBeenCalledOnce();
426426
});
427427

428+
it("stops before recording another chunk after the connection closes", async () => {
429+
const providedCfg = {
430+
channels: {
431+
irc: {
432+
host: "irc.example.com",
433+
nick: "openclaw",
434+
},
435+
},
436+
} as unknown as CoreConfig;
437+
let ready = true;
438+
const client = {
439+
isReady: vi.fn(() => ready),
440+
join: vi.fn(),
441+
sendPrivmsg: vi.fn(),
442+
quit: vi.fn(),
443+
} as unknown as IrcClient & {
444+
join: ReturnType<typeof vi.fn>;
445+
sendPrivmsg: ReturnType<typeof vi.fn>;
446+
quit: ReturnType<typeof vi.fn>;
447+
};
448+
hoisted.connectIrcClient.mockResolvedValue(client);
449+
const onDeliveryResult = vi.fn(() => {
450+
ready = false;
451+
});
452+
const onPlatformSendDispatch = vi.fn();
453+
const text = Array.from({ length: 80 }, (_, index) => `word-${index}`).join(" ");
454+
455+
await expect(
456+
sendFormattedIrcText({
457+
cfg: providedCfg,
458+
to: "#room",
459+
text,
460+
onDeliveryResult,
461+
onPlatformSendDispatch,
462+
}),
463+
).rejects.toThrow("IRC connection closed before send");
464+
465+
expect(client.sendPrivmsg).toHaveBeenCalledOnce();
466+
expect(onPlatformSendDispatch).toHaveBeenCalledOnce();
467+
expect(onDeliveryResult).toHaveBeenCalledOnce();
468+
expect(client.quit).toHaveBeenCalledOnce();
469+
});
470+
428471
it("declares message adapter durable text, media, and reply with receipt proofs", async () => {
429472
const providedCfg = {
430473
channels: {

‎extensions/irc/src/send.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,14 @@ export async function sendIrcMessages(
119119
}
120120
for (const message of preparedMessages) {
121121
opts.abortSignal?.throwIfAborted();
122+
if (!client.isReady()) {
123+
throw new Error("IRC connection closed before send");
124+
}
122125
await opts.onPlatformSendDispatch?.();
126+
opts.abortSignal?.throwIfAborted();
127+
if (!client.isReady()) {
128+
throw new Error("IRC connection closed before send");
129+
}
123130
client.sendPrivmsg(target, message.payload);
124131
recordIrcOutboundActivity(account.accountId);
125132

0 commit comments

Comments
 (0)