diff --git a/Dockerfile b/Dockerfile index 9bdfec7..2f09ee6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,7 @@ -FROM denoland/deno:alpine AS build +FROM denoland/deno:alpine-2.4.2 AS build WORKDIR /app/src COPY . . -# Set memory limits for Deno to prevent memory leaks -ENV DENO_MEMORY_LIMIT=512MB -ENV DENO_GC_INTERVAL=1000 - RUN deno install RUN deno task build @@ -16,10 +12,6 @@ COPY --from=build /app/src/import_map.json . ENV ORIGIN=http://localhost:3000 -# Set memory limits for runtime to prevent memory leaks -ENV DENO_MEMORY_LIMIT=512MB -ENV DENO_GC_INTERVAL=1000 - RUN deno cache --import-map=import_map.json ./build/index.js EXPOSE 3000 diff --git a/src/lib/data_structures/websocket_pool.ts b/src/lib/data_structures/websocket_pool.ts index 5efcdf5..5eda81a 100644 --- a/src/lib/data_structures/websocket_pool.ts +++ b/src/lib/data_structures/websocket_pool.ts @@ -211,6 +211,7 @@ export class WebSocketPool { } } this.#pool.clear(); + console.debug('[WebSocketPool] Pool drained successfully'); } @@ -252,6 +253,8 @@ export class WebSocketPool { this.#clearIdleTimer(handle); // Clean up event listeners to prevent memory leaks + // AI-NOTE: Code that checks out connections should clean up its own listener callbacks before + // releasing the connection to the pool. if (handle.ws) { handle.ws.onopen = null; handle.ws.onerror = null; @@ -261,7 +264,9 @@ export class WebSocketPool { const url = this.#normalizeUrl(handle.ws.url); this.#pool.delete(url); + console.debug(`[WebSocketPool] Removed socket for ${url}, pool size: ${this.#pool.size}`); + this.#processWaitingQueue(); }