Error: spawn EMFILE Node js - node.js

I am getting this error. While a person logs in to the application, logs are entered into a file using utilityWrapper. This file is read/Written when ever some activity is happening in the application. Then suddenly after some time
'throw errnoException(process._errno, 'spawn');
Error: spawn EMFILE
at errnoException (child_process.js:988:11)
at ChildProcess.spawn (child_process.js:935:11)
at Object.exports.spawn (child_process.js:723:9)
at Object.Logger (/web/utilityWrapper.js:21:17)
at process.env.NODE_TLS_REJECT_UNAUTHORIZED (/web/server.js:141:17)
at process.EventEmitter.emit (events.js:95:17)
at process._fatalException (node.js:272:26)
This error come up.
Please Help me.

This had happened due to various reasons. The code had many console.logs, which was printing many things on the command prompt on which the server was running. As it was writing to a file, it was using a file descriptor(fd). The ulimit of file descriptor is 1024.
using the command
lsof - -i -n -P | grep nodejs
I was able to capture the information about each fd.
Fd count used to increase when a user loogged into the application.The ldap sockets and mysql db connections also consumed a large amount of fd's.
So guys keep these points in mind when you get this kind of Error.

Related

What's "EIO: i/o error, write" in node.js and how do I eliminate it?

I have a node.js app using elasticsearch to gather error data and notify relevant stack holders. It starts to give me errors lately (no change has made to the code):
write EIO
Error: write EIO
at afterWriteDispatched (internal/stream_base_commons.js:154:25)
at writeGeneric (internal/stream_base_commons.js:145:3)
at WriteStream.Socket._writeGeneric (net.js:783:11)
at WriteStream.Socket._write (net.js:795:8)
at doWrite (_stream_writable.js:385:12)
at writeOrBuffer (_stream_writable.js:367:5)
at WriteStream.Writable.write (_stream_writable.js:307:12)
at Stdio.write (/project/node_modules/elasticsearch/src/lib/loggers/stdio.js:58:6)
at Stdio.onError (/project/node_modules/elasticsearch/src/lib/loggers/stdio.js:70:8)
at Log.wrapper (/project/node_modules/lodash/lodash.js:4929:19)
at Log.emit (events.js:315:20)
at Log.error (/project/node_modules/elasticsearch/src/lib/log.js:239:17)
at checkRespForFailure (/project/node_modules/elasticsearch/src/lib/transport.js:298:18)
at HttpConnector.<anonymous> (/project/node_modules/elasticsearch/src/lib/connectors/http.js:171:7)
at ClientRequest.wrapper (/project/node_modules/lodash/lodash.js:4929:19)
at ClientRequest.emit (events.js:315:20)
I suspect this has to do with some type of I/O error on the disk. What can I do to eliminate the error? I am using Node.js v14.0.0 and elasticsearch (npm package) 16.7.1.
This can be caused by multiple reasons:
If you are using Windows is most likely a unicode issue you can fix by executing chp command like this chcp 850 but if you need Unicode characters then iconv-lite module should help
When trying to write to a closed terminal
Disk related issues, like the disk is full or OS issues... when trying to write the output
Try to reinstall the modules to the latest version and from scratch since maybe you are using a buggy module or it wasn't installed correctly
This turns out to be a bug in ElasticSearch's log feature due to the fact it is writing to the stdio synchronously. We will either have to turn off the log or use a third party logger.

Node.js: Writing to system files with fs.writeFileSync

I am trying to write to a system file under /sys/kernel/config/usb_gadget with fs.writeFileSync but when writing "" as the contents, the file remains unchanged (with original contents in tact) and results in
Error: EBUSY: resource busy or locked, write
at Object.writeSync (fs.js:581:3)
at Object.writeFileSync (fs.js:1275:26)
at Socket.<anonymous> (/opt/sterling/ip-kvm-interface/app.js:249:6)
at Socket.emit (events.js:210:5)
at /opt/sterling/ip-kvm-interface/node_modules/socket.io/lib/socket.js:528:12
at processTicksAndRejections (internal/process/task_queues.js:75:11) {
errno: -16,
syscall: 'write',
code: 'EBUSY'
}
when writing some other contents. Permissions for the destination write file are 777.
Is fs.writeFileSync incapable of writing to files under sys or am I missing something else?
Using fsuser /sys/kernel/config/usb_gadget/kvm-gadget/UDC returns nothing (even when Node process is running) and lsof | grep /sys/kernel/config/usb_gadget/kvm-gadget/UDC also returns nothing.
Am I going to have to spawn an echo process to get this to work (not preferred but crossed my mind - since not sure how I would convert it to synchronous task)?
https://github.com/nodejs/help/issues/2459
Are there undocumented limitations to fs.writeFileSync that I am unaware of?
Nothing specific to fs.writeFileSync(), you can get the same error
with a plain C program.
/sys/kernel/config/usb_gadget is not a real file, it's a communication
channel with the kernel's usb gadget driver. It's that driver that is
returning the error.
(I could point you to the line of code if you're really interested.
It's drivers/usb/gadget/configfs.c in the kernel source tree in any
case.)

500 Internal Server Error for URL: http://localhost:8100/api/timeline

500 Internal Server Error for URL:http://localhost:8100/api/timeline dev4living/HeyCommunity
I am trying to run a dev4living/HeyCommunity webApp on a local host but i'm getting the following error:
Error: connect EADDRINUSE 127.0.0.1:8100
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
http://localhost:8100/
-i used the lastest update dev-playing : dev4living/HeyCommunity-backend and dev4living/HeyCommunity-frontendenter code here
-What should i do to fix this error?
-Your assistance will be very much appreciated.
The error states that the port you are trying to use is already occupied. Please check the app running in the port 8100 and stop that and try to run the app again. Changing the port number to something else apart from 8100 will also solve the problem.
The error is pretty self-explanatory buddy. It just means that the address you have used, i.e, the port number is currently in use by something else.
2 possible solutions:
Simply change the port number
using cmd to get the list of processes running. Identify the process running on that port. And use taskkill -pid command. Refer this stack overflow post for details regarding this method

Parse Server + Express - Issues with ParseError and site dying/restarting

I have deployed a Bitnami Parse stack to a Google Cloud VM. This stack is basically Apache running as a proxy, Then a MEAN stack handling parse server and dashboard etc.
Everything appears to be working fine when accessing the dashboard and sending individual CURL requests to test it's all available.
However, there appears to be a fatal flaw in that. When Parse returns one of it's errors e.g.
{"code":101,"error":"Object not found."}
Express sees it as an uncaught exception and dies. Now I realise that it's intentional behaviour (There's enough information out there as to why you don't want to persist after an uncaught exception)
The Bitnami stack uses Forever to run the Parse Server, but as you can see from the logs I will include below, you still run into issues with refused connections.
2016-11-25T11:41:16+00:00 DEBUG (7): {"code":101,"error":"Object not found."}
2016-11-25T11:41:16+00:00 DEBUG (7): Failed to connect to X.X.X.X: Connection refused
2016-11-25T11:41:17+00:00 DEBUG (7): Failed to connect to X.X.X.X: Connection refused
2016-11-25T11:41:17+00:00 DEBUG (7): Failed to connect to X.X.X.X: Connection refused
2016-11-25T11:41:17+00:00 DEBUG (7): Failed to connect to X.X.X.X: Connection refused
Meanwhile in the Forever logs:
Error generating response. ParseError { code: 101, message: 'Object not found.' } code=101, message=Object not found.
[object Object]
/opt/bitnami/apps/parse/htdocs/node_modules/parse-server/lib/ParseServer.js:425
throw err;
^
Error: EACCES: permission denied, open '/opt/bitnami/apps/parse/htdocs/logs/parse-server.info.2016-11-25'
at Error (native)
error: Forever detected script exited with code: 7
error: Script restart attempt #1
parse-server running on port 1337
parse-dashboard running on port 4040
So you can see that immediately following a Parse error being returned, The service is unavailable until Forever can restart the Parse Server.
This issue appears that it would affect all users as well, so if one user receives an exception, all users lose connection for a brief period.
So the question is, how should this be properly handled? Is Parse + Express not the way to go about it? Or is there some method of configuring Node or Express to return the API error to the requester, without Express dying (And without having to fall into the trap of using uncaughtException to keep Node alive)
Any help would be much appreciated, thank you
The logs from Forever said it's EACCES error, that means ParseServer couldn't access the log file and not able to write the info log in it.
Error: EACCES: permission denied, open '/opt/bitnami/apps/parse/htdocs/logs/parse-server.info.2016-11-25'
at Error (native)
error: Forever detected script exited with code: 7
error: Script restart attempt #1
parse-server running on port 1337
parse-dashboard running on port 4040
I think you have to change the /opt/bitnami/apps/parse/htdocs/logs with proper permission so that ParseServer can write log files in it.

Socket Hang Up on Nodejitsu, What does it mean?

I'm getting socket hang up errors on Nodejitsu, what does it mean?
error: Error running command deploy
error: socket hang up
error: Error: socket hang up
error: at createHangUpError (http.js:1107:15)
error: at Socket.onend (http.js:1188:27)
error: at TCP.onread (net.js:369:26)
info: Nodejitsu not ok
Two things that you might be doing that cause this:
Make sure you're using port > 1024 (no sudo) Make sure your app is <
50mb disk space
If this doesn't work please either email support at nodejitsu or visit #nodejitsu at irc.freenode.org

Resources