denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.21k stars 5.41k forks source link

server.shutdown() leaks serverWebSocket #22387

Open e3dio opened 9 months ago

e3dio commented 9 months ago

Version: Deno 1.40.4

server.shutdown() should wait for websockets to close to prevent leaking serverWebSocket, abort() should force close websockets

const port = 3006;

Deno.test('httpServerWebSocketShutdown', async t => {
  const wsOpen = Promise.withResolvers();
  const server = Deno.serve({ port }, req => {
    const { socket, response } = Deno.upgradeWebSocket(req);
    socket.onopen = wsOpen.resolve;
    return response;
  });
  const ws = new WebSocket(`ws://localhost:${port}`);
  await wsOpen.promise;
  await server.shutdown();
});
error: Leaking resources: serverWebSocket
mmastrac commented 9 months ago

Thank you for the report. I think we should probably wait for all WS connections to drain on shutdown, and terminate forcefully on abort.