This repository demonstrates a memory leak in Astro's Node adapter when used in middleware mode with Fastify (and potentially other Node.js servers).
When Astro's SSR handler is used as middleware rather than in standalone mode, it causes an EventEmitter MaxListenersExceededWarning in the Node logs. This happens when static pages are served, as Astro creates cleanup listeners in createRequest that never get removed.
(node:12345) MaxListenersExceededWarning: Possible EventEmitter memory leak detected.
11 close listeners added to [Socket]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
- Node.js 18+
- pnpm (or npm/yarn)
pnpm installpnpm run buildnode --trace-warnings server.mjsThe server will start at http://localhost:4321
Open http://localhost:4321 and refresh the page multiple times.
Watch for MaxListenersExceededWarning in the console output.