Skip to content

fa-sharp/astro-middleware-leak

Repository files navigation

Astro Middleware Memory Leak Reproduction

This repository demonstrates a memory leak in Astro's Node adapter when used in middleware mode with Fastify (and potentially other Node.js servers).

The Issue

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.

Log example

(node:12345) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 
11 close listeners added to [Socket]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit

Setup

Prerequisites

  • Node.js 18+
  • pnpm (or npm/yarn)

Installation

pnpm install

Build

pnpm run build

Reproducing the Leak

Step 1: Start the server with trace warnings enabled

node --trace-warnings server.mjs

The server will start at http://localhost:4321

Step 2: Make multiple requests to index page

Open http://localhost:4321 and refresh the page multiple times.

Step 3: Watch console output

Watch for MaxListenersExceededWarning in the console output.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors