Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix: Abort follow-up generation when the client disconnects

Blue Mousec0feae0c3e24
diff --git a/backend/apps/cloud/src/ai/ai.controller.ts b/backend/apps/cloud/src/ai/ai.controller.ts
index 535f9dbe2..2750f8f02 100644
--- a/backend/apps/cloud/src/ai/ai.controller.ts
+++ b/backend/apps/cloud/src/ai/ai.controller.ts
@@ -411,6 +411,8 @@ export class AiController {
() => controller.abort(),
FOLLOW_UPS_TIMEOUT_MS,
)
+ const onClientClose = () => controller.abort()
+ res.on('close', onClientClose)
try {
const followUps = await Promise.race([
this.aiService.generateFollowUps(
@@ -436,6 +438,7 @@ export class AiController {
)
} finally {
clearTimeout(timeoutHandle)
+ res.off('close', onClientClose)
}
}