#4660·nitro

Cached handler with `fs` storage runs many times per expiry

Author: edihaslerCreated Sep 23, 2026Updated Sep 28, 2026
Labelsbug

Environment

  • nitropack: 2.13.4 (also reached through Nuxt 4.5.1 routeRules: { swr })
  • Node.js: 26.1.0
  • OS: Windows 11
  • Preset: node-server
  • Cache storage: { driver: 'fs' }

Reproduction

https://github.com/edihasler/nitro-swr-fs-cache-race

bash
pnpm install && pnpm build
pnpm start   # terminal 1
pnpm load    # terminal 2: 40 concurrent clients, 12 s

Describe the bug

A handler defined with defineCachedEventHandler(handler, { swr: true, maxAge: 5 }) should run once per expiry. With the fs cache driver and 40 concurrent clients it runs 307 times in 12 seconds instead of 3. The same app with the default memory driver runs it exactly 3 times.

Cache driver Initial fill 1st expiry 2nd expiry Total
fs 40 125 142 307
memory 1 1 1 3

The duplicates start both on the initial fill and on every stale revalidation, so the deduplication through pending is effectively lost whenever the storage write is slow.

Additional context

No response

Logs

bash