Skip to content

test: reproduce filesLimit Premature close on buffered bodies (10.1.1 regression) - #641

Closed
noahnu wants to merge 1 commit into
fastify:mainfrom
noahnu:repro/files-limit-premature-close-on-buffered-body
Closed

noahnu wants to merge 1 commit into
fastify:mainfrom
noahnu:repro/files-limit-premature-close-on-buffered-body

Conversation

@noahnu

@noahnu noahnu commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR adds failing regression tests only (no fix). CI is expected to be red until the issue is fixed.

On @fastify/multipart@10.1.1, exceeding limits.files while consuming parts with part.toBuffer() often throws ERR_STREAM_PREMATURE_CLOSE (Premature close) instead of FilesLimitError (FST_FILES_LIMIT) when the request body is fully buffered up front.

This appears to be an unintended side effect of the GHSA-vmph-573x-85f6 fix that stopped clearing currentFile in onError: filesLimit cleanup now destroys the in-flight part stream, racing ahead of the FilesLimitError delivered on the async iterator.

Passes on 10.1.0 / fails on 10.1.1

npm test -- test/multipart-files-limit-buffered-body.test.js

Why existing filesLimit tests still pass

They use form.pipe(req), which streams the body slowly enough that the previous part is usually fully consumed before filesLimit fires. The regression shows up with:

  • fastify.inject({ payload: form.getBuffer() })
  • http.request(...); req.end(form.getBuffer())

Both are common in apps and Fastify tests.

Related

Will also open an issue with a write-up; this PR is the executable repro.

Adding failing coverage that shows FilesLimitError is replaced by
ERR_STREAM_PREMATURE_CLOSE when the multipart body is fully buffered
(fastify.inject or http end(buffer)) before parts are consumed.

Existing filesLimit tests still pass because they stream via form.pipe.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant