Skip to content

Commit f75789f

Browse files
authored
fix(delivery): log failDelivery errors instead of silently swallowing (#84449)
Replace empty .catch(() => {}) on two failDelivery calls with log.warn() so delivery queue mark-failed errors leave a diagnostic trail instead of being silently discarded. Signed-off-by: Sebastien Tardif <[email protected]>
1 parent 5c866a1 commit f75789f

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

src/infra/outbound/deliver.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,6 +2582,45 @@ describe("deliverOutboundPayloads", () => {
25822582
);
25832583
});
25842584

2585+
it("logs a warning when failDelivery rejects on bestEffort partial failure (#83113)", async () => {
2586+
queueMocks.failDelivery.mockRejectedValueOnce(new Error("queue storage down"));
2587+
2588+
await runBestEffortPartialFailureDelivery();
2589+
2590+
expect(queueMocks.failDelivery).toHaveBeenCalledWith(
2591+
"mock-queue-id",
2592+
"partial delivery failure (bestEffort)",
2593+
);
2594+
const warnCall = requireMockCall(logMocks.warn, "warn");
2595+
const warnMessage = String(warnCall[0]);
2596+
expect(warnMessage).toContain("failed to mark queued delivery");
2597+
expect(warnMessage).toContain("mock-queue-id");
2598+
expect(warnMessage).toContain("queue storage down");
2599+
});
2600+
2601+
it("logs a warning when failDelivery rejects in the error handler (#83113)", async () => {
2602+
const sendMatrix = vi.fn().mockRejectedValue(new Error("native send failed"));
2603+
queueMocks.failDelivery.mockRejectedValueOnce(new Error("db connection lost"));
2604+
2605+
await expect(
2606+
deliverOutboundPayloads({
2607+
cfg: {},
2608+
channel: "matrix",
2609+
to: "!room:example",
2610+
payloads: [{ text: "hello" }],
2611+
deps: { matrix: sendMatrix },
2612+
queuePolicy: "required",
2613+
}),
2614+
).rejects.toThrow("native send failed");
2615+
2616+
expect(queueMocks.failDelivery).toHaveBeenCalledWith("mock-queue-id", expect.any(String));
2617+
const warnCall = requireMockCall(logMocks.warn, "warn");
2618+
const warnMessage = String(warnCall[0]);
2619+
expect(warnMessage).toContain("failed to mark queued delivery");
2620+
expect(warnMessage).toContain("mock-queue-id");
2621+
expect(warnMessage).toContain("db connection lost");
2622+
});
2623+
25852624
it("writes raw payloads to the queue before normalization", async () => {
25862625
const sendMatrix = vi.fn().mockResolvedValue({ messageId: "m-raw", roomId: "!room:example" });
25872626
const rawPayloads: DeliverOutboundPayload[] = [

src/infra/outbound/deliver.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,13 @@ async function deliverOutboundPayloadsWithQueueCleanup(
12951295
}
12961296
if (queueId) {
12971297
if (hadPartialFailure) {
1298-
await failDelivery(queueId, "partial delivery failure (bestEffort)").catch(() => {});
1298+
await failDelivery(queueId, "partial delivery failure (bestEffort)").catch(
1299+
(err: unknown) => {
1300+
log.warn(
1301+
`failed to mark queued delivery ${queueId} as failed after partial failure; continuing best-effort delivery: ${formatErrorMessage(err)}`,
1302+
);
1303+
},
1304+
);
12991305
} else {
13001306
if (platformSendStarted) {
13011307
await markQueuedPlatformOutcomeUnknown({
@@ -1325,7 +1331,11 @@ async function deliverOutboundPayloadsWithQueueCleanup(
13251331
if (isDeliveryAbortError(err)) {
13261332
await ackDelivery(queueId).catch(() => {});
13271333
} else if (!platformResultsReturned) {
1328-
await failDelivery(queueId, formatErrorMessage(err)).catch(() => {});
1334+
await failDelivery(queueId, formatErrorMessage(err)).catch((failErr: unknown) => {
1335+
log.warn(
1336+
`failed to mark queued delivery ${queueId} as failed: ${formatErrorMessage(failErr)}`,
1337+
);
1338+
});
13291339
}
13301340
}
13311341
throw err;

0 commit comments

Comments
 (0)