EMFILE, too many open file - node.js

[INFO] system - { codeblock: 'catch copy image', error: { [Error: EMFILE, too many open files './uploads/54f911bad366ed/document/document_559dfb750f15617.png']
errno: 20,
code: 'EMFILE',
path: './uploads/54f911bad366ed/document/document_559dfb750f15617.png',
syscall: 'open' } }
Regret I don't have enough reputation to make comment in this thread (node and Error: EMFILE, too many open files) so I have to create a new one to ask question.
My application has above error. I checked the log and the error occurred during a copying process (of template to user's login account and an admin account) when users first login.
I don't know idea why because it also occurred on some users account that the user did not login.
Can anyone help?

Related

How to change file system permission on cyclic.sh?

The bounty expires in 2 days. Answers to this question are eligible for a +50 reputation bounty.
Artaza Sameen is looking for an answer from a reputable source.
Cyclic is a web hosting platform like Heroku
I am trying to create a file on cyclic in my NodeJS API. But, it turns out that the folder permission is write-only. How do I change folder permission to enable file writes in cyclic.sh
Here is the Error:
Error: EROFS: read-only file system, open 'public/ogData/https!www.stackoverflow.com.json'
at Object.openSync (node:fs:600:3)
at Object.writeFileSync (node:fs:2221:35)
at saveOGInJson (file:///var/task/utils.mjs:12:6)
at cacheOGInfo (file:///var/task/utils.mjs:88:5)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///var/task/index.mjs:18:16 {
errno: -30,
syscall: 'open',
code: 'EROFS',
path: 'public/ogData/https!www.stackoverflow.com.json'
}

Hexo init fail on windows 10

When I try to run hexo init in Git Bash in Windows10, it fail and show following :
INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
fatal: unable to access 'https://github.com/hexojs/hexo-starter.git/': Failed to connect to localhost port 1080: Connection refused
WARN git clone failed. Copying data instead
FATAL {
err: [Error: ENOENT: no such file or directory, scandir 'C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo-cli\assets'] {
errno: -4058,
code: 'ENOENT',
syscall: 'scandir',
path: 'C:\\Users\\Administrator\\AppData\\Roaming\\npm\\node_modules\\hexo-cli\\assets'
}
} Something's wrong. Maybe you can find the solution here: %s http://hexo.io/docs/troubleshooting.html
How does it happen and how do we solve it?
I had the issue too. Tried again after a few minutes it worked. It due to bad access to github.com from China.
Try to run the same command from powershell non admin. If it does not work, try npx hexo init

Getting ENOTSUP error on nodejs 0.12.6 app running in Azure Websites

I recently upgraded by version of nodejs on my windows azure web application from 0.12.0 to 0.12.6. Since then, whenever I relaunch my app on visual studio online editor, the console reports a significant errors like these ones:
glob error { [Error: ENOTSUP, scandir 'D:\home\site\wwwroot\views\partials\recommendationModal.handlebars']
errno: -4049,
code: 'ENOTSUP',
path: 'D:\\home\\site\\wwwroot\\views\\partials\\recommendationModal.handlebars' }
glob error { [Error: ENOTSUP, scandir 'D:\home\site\wwwroot\views\partials\register.handlebars']
errno: -4049,
code: 'ENOTSUP',
path: 'D:\\home\\site\\wwwroot\\views\\partials\\register.handlebars' }
glob error { [Error: ENOTSUP, scandir 'D:\home\site\wwwroot\views\partials\search.handlebars']
errno: -4049,
code: 'ENOTSUP',
path: 'D:\\home\\site\\wwwroot\\views\\partials\\search.handlebars' }
glob error { [Error: ENOTSUP, scandir 'D:\home\site\wwwroot\views\partials\spinningWheel.handlebars']
errno: -4049,
code: 'ENOTSUP',
path: 'D:\\home\\site\\wwwroot\\views\\partials\\spinningWheel.handlebars' }
glob error { [Error: ENOTSUP, scandir 'D:\home\site\wwwroot\views\partials\stylesFilterButtons.handlebars']
errno: -4049,
code: 'ENOTSUP',
path: 'D:\\home\\site\\wwwroot\\views\\partials\\stylesFilterButtons.handlebars' }
All of the files in the error descriptions are handlebars partials.
I run the same app on my local development environment (linux with nodejs 0.12.6) and these errors never show up.
At first glance, it looks like there is something broken on azure websites when running your app on 0.12.6, but I'd like to post this situation here in SO to see if other people have faced the same issue and how they managed to resolve it.
This very much looks like this bug. Sounds like you may have glob 5.0.13 or earlier installed. Try 5.0.14 and it will hopefully solve your problem.
Just had the same issue with Azure. Mine happened to be glob as one comment stated.
express-handlebars has fixed this issue if you update to 3.0.0

Node Agenda Scheduler Mongo errno: 20, code: 'EMFILE'

I am running a node scheduler using agenda. It runs fine for around 30 minutes and then it starts displaying this error.
{ [Error: EMFILE, open 'log/scheduler.log'] errno: 20, code: 'EMFILE', path: 'log/scheduler.log' }
{ [Error: EMFILE, open 'log/scheduler.log'] errno: 20, code: 'EMFILE', path: 'log/scheduler.log' }
[Error: failed to connect to [localhost:27017]]
[Error: failed to connect to [localhost:27017]]
[Error: failed to connect to [localhost:27017]]
[Error: failed to connect to [localhost:27017]]
[Error: failed to connect to [localhost:27017]]
I am using node js with mongo db deployed on a EC2 instance.
The code I wrote is here:
https://github.com/kelvinblade/bluesky-scheduler2
Any help would be appreciated.
EMFILE occurs when too many file descriptors are open as there is limitation in an os for the number of descriptors to be opened by a process.
You can reset this restriction by editing this file
/etc/sysctl.conf
or a more graceful approach is to use some module that would take care and have a connectionpool to monitor over the opened file descriptors.
You may try node-graceful-fs or filequeue
Git source :
https://github.com/isaacs/node-graceful-fs
https://github.com/treygriffith/filequeue.git
Install apppropriate node modules by
npm install node-graceful-fs
or
npm install filequeue
and replace your fs from default to
var fs = require('graceful-fs')
or
var fs = new FileQueue(100);
Personally i feel filequeue is better queuing system.

NodeJS errno 37 on socket.connect

I'm trying to connect to multiple hosts in succession, this is the code to resolve the ip address and socket.connect() to each domain name (line[1]). This works on it's own but returns an errno 37 error when run in quick succession with different hosts. The best information I have on the error is:
" code: 'EPROTO', description: 'protocol error' "
Code:
$.connect(port, line[1], function() {
this.write(request);
});
Error:
{ [Error: connect Unknown system errno 37]
code: 'Unknown system errno 37',
errno: 'Unknown system errno 37',
syscall: 'connect' }
How can I resolve this / why is this happening?
Thanks in advance.
EDIT: removed manual dns lookup code and added error report
duplicate with https://stackoverflow.com/questions/14672743/nodejs-crash-when-calling-socket-connect-in-quick-succession
Seems to me opening sockets in rapid succession is asking for trouble.
Try waiting in between opening the sockets and play with the amount of time needed to wait.

Resources