Repository navigation
fix(react-email): don't leak a file handle when a static file can't be read - #3812
Merged
Merged
Conversation
Contributor
|
@b84330808 is attempting to deploy a commit to the resend Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 0b05a8b The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
…e read serveStaticFile() opened a FileHandle and only closed it after a successful read. When the read failed (a directory on Linux/macOS, a locked file on Windows), the handle was left for the garbage collector, which Node.js 25+ turns into an ERR_INVALID_STATE crash of `email dev`. Read the file by path instead so nothing is left open. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Test the static file server without mocking fs: request a real directory, check that no file descriptor stays open, and move setup/cleanup to beforeEach/afterEach.
dielduarte
force-pushed
the
fix/static-file-handle-leak
branch
from
November 9, 2026 20:24
da71f5a to
0b05a8b
Compare
dielduarte
approved these changes
Nov 9, 2026
dielduarte
left a comment
Contributor
There was a problem hiding this comment.
Thanks for tracking this down, and for the clear write-up and repro in #3808! The fs.readFile(path) fix is the right one.
I pushed a few things on top and rebased onto the latest canary:
- Directories under
/staticnow return 404 instead of 500. A request like/static/used to log a stack trace and send a 500. It now gets the same 404 as a missing file. - Tests without mocking
fs. I replaced the test that spied onfs.promises.openwith one that requests a real directory and checks that no file descriptor is left open. It fails on the old code. It's skipped on Windows, which has no/dev/[fd](https://github.com/dev/fd). I also added a test for a missing file and moved setup and cleanup intobeforeEach/afterEach, so a failing assertion can't leaveprocess.cwdmocked for the rest of the file. - The same leak in
@react-email/ui.isFileAnEmailinget-emails-directory-metadata.tsopened a handle and could leak it ifstat()orreadFile()threw. It now reads by path, and a file it can't read is skipped with a warning instead of failing the whole scan. It has its own changeset.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3808.
email devserves files understatic/withserveStaticFile(). It opened the file withfs.open()and only closed the handle after a successful read, so when the read fails after the open succeeds (a request for a directory under/staticon Linux or macOS givesEISDIR; a file another program has locked on Windows givesEBUSY) theFileHandleis never closed.Node.js 24 only prints a DEP0137 warning for that. Node.js 25 made it an error, so the preview server exits the next time the garbage collector runs:
Changes:
fs.readFile(path)instead of opening a handle first, so nothing stays open when the read fails. The 404/500 handling is unchanged.react-email.Reproduction on Windows with Node.js 26.12: with
emails/static/logo.pnglocked by another process, callingserveStaticFile()and then forcing GC crashes the process before this change; after it, the request gets a 500 and the process keeps running.I used Claude Code to write this change.
Summary by cubic
Fixes #3808 and a related leak in
@react-email/ui.email devserved files understatic/by opening aFileHandleand only closing it after a successful read; when the read failed (a directory request on Linux/macOS givesEISDIR, a locked file on Windows givesEBUSY), the handle leaked. Node.js 24 prints a DEP0137 warning for that, but Node.js 25 turns it into anERR_INVALID_STATEerror that crashes the preview server at the next garbage collection. The same pattern leaked a handle while scanning the emails directory, and an unreadable file there failed the whole scan.Changes:
fs.readFile()instead of opening a handle first, so nothing stays open when the read fails; the 404/500 handling is unchanged, and requesting a directory under/staticnow returns a 404 instead of a 500.fs.promises.stat()and reads by path, skipping unreadable files with a warning instead of failing the scan.react-emailand@react-email/ui.Written for commit 0b05a8b. Summary will update on new commits.