Skip to content

fix: return callNotFound for directories without index file - #626

Merged
Tony133 merged 2 commits into
mainfrom
fix/directory-not-found-handler-sendfile
Nov 4, 2026
Merged

Tony133 merged 2 commits into
mainfrom
fix/directory-not-found-handler-sendfile

Conversation

@mcollina

@mcollina mcollina commented Nov 3, 2026

Copy link
Copy Markdown
Member

Fixes #625

Problem

Since 10.1.8, a request for a directory with no index file (and redirect off) returned an empty 200 when the not-found handler used reply.sendFile(...). It also logged FST_ERR_REP_ALREADY_SENT.

In that branch, pumpSendToReply called reply.callNotFound() without returning it. The wildcard handler now returns pumpSendToReply(...), so its promise resolved to undefined before the not-found handler finished streaming. Fastify then sent an empty reply.

Fix

return reply.callNotFound() there, the same as every other callNotFound() call in pumpSendToReply.

Tests

Added a regression test that requests /deep (a directory with no index) with a setNotFoundHandler that calls reply.sendFile('index.html'). It fails on main and passes with this change. Full suite passes with 100% coverage, and lint is clean.

🤖 Generated with Claude Code

When a directory without an index file was requested, pumpSendToReply
called reply.callNotFound() without returning it, so the route handler
promise resolved before the not-found handler finished. A not-found
handler using reply.sendFile() then produced an empty 200 response and
FST_ERR_REP_ALREADY_SENT.

Fixes #625

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@SameRainbows SameRainbows left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified locally on Node 24 and against the test suite.

Returning reply.callNotFound() cleanly preserves the thenable chain in pumpSendToReply, allowing the not-found handler's async stream to complete before Fastify terminates the response. All 18 CI matrix jobs and CodeQL checks are green.

@Tony133 Tony133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Tony133
Tony133 merged commit 55c7bc9 into main Nov 4, 2026
20 checks passed
@Tony133
Tony133 deleted the fix/directory-not-found-handler-sendfile branch November 4, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10.1.8 regression: directory without index + setNotFoundHandler sendFile returns empty 200

3 participants