-
Notifications
You must be signed in to change notification settings - Fork 120
Error: EMFILE: too many open files #396
Comments
@chsnt this indicates that there are too many open file handles in your application, is there a chance you are initializing the client in a loop? Could you share a snippet of the code you are running? |
main.js
translate.js
|
@chsnt what does the following do:
I could you try running |
i run this
and it works correctly. But when i run it without this string
i geting this error
|
try: const {Translate} = require('@google-cloud/translate').v2;
const translate = Translate({projectId: 'your-project-id'})
const tr = (text, target) => {
return new Promise ((resolve, reject)=>{
translate.translate(text, target)
.then(([result])=>resolve(result))
.catch(err=>{
console.error(err);
reject(err)
})
})
}
tr('hello', 'ru')
.then(res => console.log(res))
.catch(err => console.log(err)) Providing
|
In my system environment variables
i try this code:
and got error:
|
@chsnt could you also try setting the environment variable I'm not sure why |
@bcoe
and it works correctly (for single use). But when i use this code like a module for multiple call i had error again:
(i dont use |
@chsnt could you provide code that demonstrates how you are running this logic multiple times; my hunch is that there's a chance you're creating a |
@bcoe
(full code https://gist.github.com/chsnt/0d669b0a9509086dce829f8d0ae7257c ) translate.js
|
@chsnt the problem isn't the Translate client, I believe it's this code: getFiles(dir, function (err, files) {
pbSubr.start(files.length, 0);
files.forEach( file => {
fs.pathExists(file.replace('data\\boards\\', 'data\\boards-ru\\'))
.then(exists => {
if(!exists) {
translatorWithErrorHandle (file);
} else {
pbSubr.increment()
pbSubr.update(undefined, {dir: file.split('\\')[3]});
}
})
});
}); This is going to open all files in parallel, so if there are many files in I would potentially rewrite this like: getFiles(dir, async function (err, files) {
pbSubr.start(files.length, 0);
for (const file of files) {
const exists = await fs.pathExists(file.replace('data\\boards\\', 'data\\boards-ru\\'))
. if(!exists) {
await translatorWithErrorHandle (file);
} else {
pbSubr.increment()
await pbSubr.update(undefined, {dir: file.split('\\')[3]});
}
})
}
}); ☝️ this is pseudo code that would translate a file one at a time, assuming that As an alternative to In general, you don't want to perform a large amount of async work in a loop, because you'll create a lot of open handles at once. |
Hello, how can i fix it?
The text was updated successfully, but these errors were encountered: