fix(webhooks): ignore dispatcher cleanup failures

This commit is contained in:
Bhagya Amarasinghe
2026-05-21 18:19:58 +05:30
parent 0952fee6c7
commit c29ee83e19
2 changed files with 36 additions and 1 deletions
@@ -858,6 +858,29 @@ describe("processResponsePipelineJob", () => {
expect(mockDispatcherDestroy).toHaveBeenCalledTimes(1);
});
test("logs dispatcher cleanup failures without failing a successful webhook delivery", async () => {
const cleanupError = new Error("destroy failed");
mockPrismaWebhookFindMany.mockResolvedValue([
{
id: "webhook_123",
secret: null,
url: "https://example.com/webhook",
},
]);
mockDispatcherDestroy.mockRejectedValue(cleanupError);
await expect(processResponsePipelineJob(baseData, baseContext)).resolves.toBeUndefined();
expect(mockLoggerWarn).toHaveBeenCalledWith(
expect.objectContaining({
err: cleanupError,
webhookId: "webhook_123",
webhookUrl: "https://example.com/webhook",
}),
"Response pipeline webhook dispatcher cleanup failed"
);
});
test("destroys the pinned dispatcher when the webhook fetch throws", async () => {
mockPrismaWebhookFindMany.mockResolvedValue([
{
@@ -254,7 +254,19 @@ const createWebhookDeliveryTask = async ({
throw new Error(`Webhook delivery failed with status ${response.status}`);
}
} finally {
await dispatcher?.destroy();
try {
await dispatcher?.destroy();
} catch (cleanupError) {
logger.warn(
{
...logContext,
err: cleanupError,
webhookId: webhook.id,
webhookUrl: webhook.url,
},
"Response pipeline webhook dispatcher cleanup failed"
);
}
}
} catch (error) {
logger.error(