question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EMFILE: too many open files

See original GitHub issue

I’m running a job every second that instantiates a class, like so

const RedisService = require('../../services/redis-service');
...
const redis = new RedisService()

This job runs for awhile and then eventually goes into a fail loop with the error

EMFILE: too many open files

and points to ...services/redis-service.js as the open that exceeded whatever ulimit -n must be on my machine. I know that there are packages like graceful-fs that might be able to solve this problem, but is this just because I’m using Bree incorrectly? Is there a proper way to close the files that a job opens when it is run by Bree?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
shadowgate15commented, Nov 3, 2021

@alvin30595 I would suggest using the workerMessageHandler and do the logging work on the main process. Worker threads and logging is pretty difficult.

2reactions
r00bcommented, Feb 8, 2021

Specifically I believe the issue was that as Node worker threads exited they did not necessarily flush their file streams, thus when the number of open file streams exceeded ulimit, the parent process crashed. I think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node and Error: EMFILE, too many open files - Stack Overflow
After a number of searches I found a work around for the "too many open files" problem: var requestBatches = {}; function batchingReadFile(filename,...
Read more >
EMFILE: too many open files, watch · Issue #923 - GitHub
i'm facing below issue while generating archive in xcode node:events:371 throw er; // Unhandled 'error' event ^ Error: EMFILE: too many open ......
Read more >
How to fix the: "EMFILE: too many open files, watch" error in ...
A quick guide to how I solved a confusing React Native error.
Read more >
Quick fix for “EMFILE: too many open files error” during ... - torrito
Use graceful-fs in your webpack.config.js:. “Quick fix for “EMFILE: too many open files error” during webpack build” is published by torrito.
Read more >
Node js: Cannot start debugging: EMFILE: too many open files
Error: Error: EMFILE: too many open files, open 'd:\PrototypingQuick\VuejsApp1\VuejsApp1\node_modules\caniuse-lite\data\regions\AN.js'
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found