I am facing a strange issue with our node service.
Lots of socket file descriptors have remained open against node process and limit for open files (10240 files) against process has reached. So, I am getting EMFILE error.
Service has stalled and stopped accepting new requests as well as sending outbound requests to other services.
Nowhere in code I am EXPLICITLY dealing with socket connections.
Node process still listening on port. We are using PM2.
Similar question for Java: https://serverfault.com/questions/153983/sockets-found-by-lsof-but-not-by-netstat
Below is details of versions:
- Node version: 8.16.0
- Hapi: 14.2.0
- request: 2.88.2 (used to send outbound requests)
Commands output in console:
[CONSOLE ~]$ lsof -p [PID] | wc -l
10253
[CONSOLE ~]$ ulimit -a
.
.
file size (blocks, -f) unlimited
.
.
max memory size (kbytes, -m) unlimited
open files (-n) 10240
.
.
.
[CONSOLE ~]$ netstat -np | grep [PORT]
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
[CONSOLE ~]$ netstat -a -n | grep [PORT]
tcp 0 0 0.0.0.0:[PORT] 0.0.0.0:* LISTEN
[CONSOLE ~]$ lsof -i :[PORT]
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node [PID] glpd 15u IPv4 2270823542 0t0 TCP *:[PORT] (LISTEN)
[CONSOLE ~]$ lsof -p [PID]
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
.
.
.
node [PID] glpd 15u IPv4 2270823542 0t0 TCP *:[PORT] (LISTEN)
node [PID] glpd 16u sock 0,7 0t0 2271652082 protocol: TCP
node [PID] glpd 17u sock 0,7 0t0 2271551621 protocol: TCP
node [PID] glpd 18u sock 0,7 0t0 2271663118 protocol: TCP
node [PID] glpd 19u sock 0,7 0t0 2271662963 protocol: TCP
node [PID] glpd 20u sock 0,7 0t0 2271660595 protocol: TCP
node [PID] glpd 21u sock 0,7 0t0 2271652144 protocol: TCP
node [PID] glpd 22u sock 0,7 0t0 2271660631 protocol: TCP
node [PID] glpd 23u sock 0,7 0t0 2271662997 protocol: TCP
node [PID] glpd 24u sock 0,7 0t0 2271660660 protocol: TCP
node [PID] glpd 25u sock 0,7 0t0 2271663083 protocol: TCP
.
.
.
Has anyone come across this in Node?
EDIT:
Socket timeout for all incoming requests to this service are disabled(set to false) as it is our main processing service and we can not predict the amount of time a request can take to get processed.
request()library, every time you call it, you're making a socket that should get cleaned up if everything works successfully, but could be left hanging around a while in some error conditions. - jfriend00