Skip to content

fix: handle non-regular files in dev watcher to prevent crashes#14854

Open
RomanBaiocco wants to merge 4 commits intoremix-run:devfrom
RomanBaiocco:fix/dev-socket-file-crash
Open

fix: handle non-regular files in dev watcher to prevent crashes#14854
RomanBaiocco wants to merge 4 commits intoremix-run:devfrom
RomanBaiocco:fix/dev-socket-file-crash

Conversation

@RomanBaiocco
Copy link

@RomanBaiocco RomanBaiocco commented Mar 6, 2026

Summary

Fixes #14855

react-router dev crashes when Unix socket files (.sock) exist in the project root directory. This commonly happens when using process managers like overmind or pm2, which create socket files in the working directory.

The crash occurs because @react-router/dev's chokidar v4 watcher attempts to call fs.watch() on socket files, which fails on macOS with UNKNOWN: unknown error, watch (errno -102).

Changes

  • Extract the watcher's ignored callback into an exported isIgnoredByWatcher function for testability
  • Run cheap path-based checks before fs.statSync to avoid unnecessary syscalls on already-ignored paths
  • Filter non-regular files (sockets, pipes, etc.) via fs.statSync so chokidar never tries to watch them
  • Add an error event handler on the watcher so unexpected errors log a warning via picocolors instead of crashing the process
  • Add tests covering regular files, directories, socket files, and already-ignored paths

Reproduction

Full repro repo with steps: https://github.com/RomanBaiocco/react-router-sock-repro

Quick repro:

npx create-react-router@latest my-app
cd my-app
node -e "require('net').createServer().listen('./overmind.sock')" &
npx react-router dev  # crashes

Related

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Mar 6, 2026

Hi @RomanBaiocco,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@changeset-bot
Copy link

changeset-bot bot commented Mar 6, 2026

🦋 Changeset detected

Latest commit: 8231128

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@react-router/dev Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch
react-router Patch
react-router-dom Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch

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

@RomanBaiocco RomanBaiocco force-pushed the fix/dev-socket-file-crash branch from 001ad02 to 0d7e61f Compare March 6, 2026 16:43
@RomanBaiocco RomanBaiocco changed the base branch from main to dev March 6, 2026 16:43
@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Mar 6, 2026

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@RomanBaiocco RomanBaiocco force-pushed the fix/dev-socket-file-crash branch from abfc22e to b5a8e19 Compare March 6, 2026 17:05
@RomanBaiocco RomanBaiocco marked this pull request as ready for review March 6, 2026 17:07
@RomanBaiocco RomanBaiocco force-pushed the fix/dev-socket-file-crash branch 2 times, most recently from ce9b080 to 990409d Compare March 6, 2026 17:33
RomanBaiocco and others added 3 commits March 12, 2026 15:55
The dev file watcher crashes when Unix socket files (e.g. from overmind
or pm2) exist in the project root. chokidar v4 calls fs.watch() on
these files, which fails on macOS with errno -102 (UNKNOWN).

- Extract watcher ignore logic into an exported `isIgnoredByWatcher`
  function for testability
- Run cheap path-based checks before the fs.statSync call to avoid
  unnecessary syscalls on already-ignored paths
- Filter non-regular files (sockets, pipes, etc.) via fs.statSync
- Add an error handler on the watcher so unexpected errors log a
  warning instead of crashing the process

Fixes: https://github.com/RomanBaiocco/react-router-sock-repro
Related: paulmillr/chokidar#1391
@pcattori pcattori force-pushed the fix/dev-socket-file-crash branch from 9fb8a25 to 6091dc8 Compare March 12, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants