Skip to content

Comments

fix: enable polling in chokidar to prevent EMFILE errors on macOS#13281

Merged
czubocha merged 1 commit intomainfrom
sc-3769
Jan 20, 2026
Merged

fix: enable polling in chokidar to prevent EMFILE errors on macOS#13281
czubocha merged 1 commit intomainfrom
sc-3769

Conversation

@czubocha
Copy link
Contributor

@czubocha czubocha commented Jan 20, 2026

Summary

  • Enable polling mode (usePolling: true) in chokidar file watchers to prevent "EMFILE: too many open files" errors on macOS

Context

In v4.31.0, we upgraded chokidar from v3.6.0 to v4.0.3. Chokidar v4 removed bundled fsevents support (native macOS file watching), causing the file watcher to fall back to fs.watch which creates one file descriptor per file/directory. On larger projects, this can exhaust the OS file descriptor limit, resulting in EMFILE: too many open files errors during serverless dev.

Enabling polling mode (usePolling: true) switches chokidar to use fs.watchFile which avoids this issue by using a different file watching mechanism that doesn't exhaust file descriptors.

Fixes #13268

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced file watching reliability for large projects on macOS by switching to polling-based file detection

✏️ Tip: You can customize this high-level summary in your review settings.

@czubocha czubocha requested a review from eahefnawy January 20, 2026 14:29
@Mmarzex
Copy link
Contributor

Mmarzex commented Jan 20, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

The changes enable polling-based file watching in chokidar configurations across two modules to mitigate EMFILE errors on macOS when running Serverless Framework dev mode with large projects. After chokidar v4 removed fsevents support, polling is explicitly enabled to ensure reliable file change detection.

Changes

Cohort / File(s) Summary
File watcher polling configuration
packages/engine/src/lib/devMode/index.js, packages/serverless/lib/plugins/aws/dev/index.js
Adds usePolling: true to chokidar file watcher instances in dev/watch functions with explanatory comment about mitigating EMFILE errors on macOS after chokidar v4 removed fsevents support. Changes replace native file system event detection with polling-based approach.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit hops through files with glee,
Polling watches, now they're free!
No more EMFILE woes, macOS flies,
Large projects bloom before our eyes!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: enabling polling in chokidar to prevent EMFILE errors on macOS, which matches the core objective of the PR.
Linked Issues check ✅ Passed The PR implements polling mode in chokidar file watchers to prevent file descriptor exhaustion and EMFILE errors on macOS, directly addressing issue #13268's requirement to restore reliable file watching on larger projects.
Out of Scope Changes check ✅ Passed All changes are focused on enabling polling in chokidar configuration across two files, directly addressing the EMFILE error issue with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@eahefnawy eahefnawy left a comment

Choose a reason for hiding this comment

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

Looks good. But what's the difference between the engine code/change the the plugin code/change?

@czubocha czubocha merged commit 1da1bb5 into main Jan 20, 2026
13 checks passed
@czubocha czubocha deleted the sc-3769 branch January 20, 2026 17:43
@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serverless dev throws "EMFILE: too many open files" on macOS in v4.31.0

3 participants