From 131f09952be1d9110c4cb9b834b9683d81511366 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 7 Mar 2025 16:17:14 +0000 Subject: [PATCH] explicit exit, fix error in ingestor --- packages/appview/src/index.ts | 3 ++- packages/appview/src/ingestors/jetstream.ts | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/appview/src/index.ts b/packages/appview/src/index.ts index ae2d877..637c7e6 100644 --- a/packages/appview/src/index.ts +++ b/packages/appview/src/index.ts @@ -120,7 +120,7 @@ export class Server { async close() { this.ctx.logger.info('sigint received, shutting down') await this.ctx.ingester.destroy() - return new Promise((resolve) => { + await new Promise((resolve) => { this.server.close(() => { this.ctx.logger.info('server closed') resolve() @@ -135,6 +135,7 @@ const run = async () => { const onCloseSignal = async () => { setTimeout(() => process.exit(1), 10000).unref() // Force shutdown after 10s await server.close() + process.exit(0) } process.on('SIGINT', onCloseSignal) diff --git a/packages/appview/src/ingestors/jetstream.ts b/packages/appview/src/ingestors/jetstream.ts index d9ac499..5dcae9c 100644 --- a/packages/appview/src/ingestors/jetstream.ts +++ b/packages/appview/src/ingestors/jetstream.ts @@ -93,6 +93,7 @@ export class Jetstream { private cursor?: number private ws?: WebSocket private isStarted = false + private isDestroyed = false private wantedCollections: string[] constructor({ @@ -133,6 +134,7 @@ export class Jetstream { start() { if (this.isStarted) return this.isStarted = true + this.isDestroyed = false this.ws = new WebSocket(this.constructUrlWithQuery()) this.ws.on('open', () => { @@ -159,13 +161,16 @@ export class Jetstream { }) this.ws.on('close', (code, reason) => { - this.logger.error(`Jetstream closed. Code: ${code}, Reason: ${reason}`) + if (!this.isDestroyed) { + this.logger.error(`Jetstream closed. Code: ${code}, Reason: ${reason}`) + } this.isStarted = false }) } destroy() { if (this.ws) { + this.isDestroyed = true this.ws.close() this.isStarted = false } -- 2.51.2