Error: read ENOTCONN: Nodejs, error after running the project - node.js

Node project worked fine couple of months ago, now after implementation of sockets, when trying to run the app, i see the following error:
Error in console(git bash)
I'm using win 10, tried changing Node versions(4.7, 6.10, 7.2, 7.9), No result there.
The port I'm using is not busy.
We are using socket.io, tried to remove the part of code, that uses the module, but unexpectedly, it did not help.
Any ideas ?
Update: Works fine on OS X, and doesn't work on 3 different win 10 oter computers.

You should listen to the error event.
socket.on('error', function () {
// Error logging here
});

Related

nodejs child_process spawn silently fails on windows

I'm wondering if anyone has had a similar problem with nodejs child_process spawn on windows.
I can no longer execute a nodejs script that calls child_proces.spawn. (This was working fine until yesterday, when suddenly node stopped working properly. No new software installed or anything that I am aware of that could have triggered this.) The call to spawn simply exits the process and fails with no error code, no error message, just exits silently.
My testcase script looks like this:
const { spawn } = require('child_process');
console.log('test 1');
try {
spawn('c:\\windows\\system32\\cmd.exe', ['/d', '/c', 'dir'], { stdio: 'inherit' });
console.log('test 2');
} catch (err) {
console.log('err', err);
}
The output looks like this:
PS C:\test> node .\index.js
test 1
PS C:\test>
Running nodejs v14.17.1 on Windows 10. (I've also tried with nodejs v10, v12, v14.15.1 and v16, both x86 and x64 varieties - there is no difference in behavior.) I've tried uninstalling nodejs and re-installing multiple times. I've tried with Powershell and with the windows Command Prompt.
I had this problem intermittently about 6 months ago and previously just rebooting windows seemed to clear this up. I'm guessing that something has been corrupted in the OS somehow.
Tracing through nodejs through the nodejs debug inspect shows it hits this line and then just quits silently when stepping into this line of code:
https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/lib/internal/child_process.js#L390
const err = this._handle.spawn(options);
I don't see anything odd/wrong in the options object and I've tried with various different environment variable settings for PATH, etc.
UPDATE:
Looks like things work fine if windows is started in safe mode or started with early launch anti-malware protection disabled. Now, I'm suspecting something with anti-virus software is interfering here.
Turns out some new anti-virus rules were blocking all processes attempting to spawn a new cmd.exe child process.

How do I get a response/information from a hanging pgPool.connect()?

I am using the pg package (node.js), and for some reason the connect function gives me nothing. My code gets hung up on that line and I'm unable to see any errors, what's wrong, or what's happening.
i.e.
console.log("HERE");
await pgPool.connect()
console.log("NOW HERE") //this line never prints
I've tried a bunch of variations too:
console.log("HERE");
const client = await pgPool.connect()
console.log(client) //this line never prints
Does anyone know how to get a verbose stream from pg? My pg version is 7.15.0 and my npm version is 6.14.4
I've tried waiting it out for over an hour. For friends running the same code from the same branch on their local machines it connects in under a second. I've confirmed they have the same version of pg as me.
I am able to connect directly to the database using psql in a separate terminal without issues (it immediately connects in < 1 second)
Updated my pg to 8.2.1 and it solved the problem. Must be an incompatibility issue with an earlier version

Electron app.on('ready'... never being called and electron window never showing. Seemingly tied to specific Git repository

Summary
I'm new to Electron development, and helping to lead a small project at work creating an electron application. After working inside the Git repository for a day or so, the electron window suddenly stopped appearing. I've determined that the function callback I give in app.on('ready' callback) is never being called.
My workstation setup:
NodeJS version: 12.9.0 (Also tested with 10.16.3)
Yarn Version: 1.17.3
OS: Windows 10 Enterprise
Originally, I was loosely following Ryan Brockhoff's Medium post about using Electron with React when electron started malfunctioning, but I've since cut a brand new Git branch and set up only an extremely minimal Electron project, and the same problem appears.
Electron does not malfunction the same way system-wide. I'm able to run the electron-api-demos perfectly. In addition, an older test directory where I was experimenting with electron still functions.
When I attempt to run the broken electron repository, Task Manager does show three electron processes as children under the command line process. When I run a well-functioning electron process, the electron process is shown as a parent process
I confirmed the 'ready' callback function is never being called through placing console.log statements inside the function, as well as a print statement when the callback is being assigned. the callback assignment print statement is being reached, and I can see the output on the console, but the print statement inside the callback function is never being reached, and that output is never being printed to the console.
Troubleshooting
I've done many troubleshooting steps at this point:
Troubleshooting: I deleted and re-cloned the Git repository elsewhere on my computer
Result: problem persists
Troubleshooting: Let the program run for a while, maybe it needs to set something up before it's ready
Result: After 10+ minutes, no change
Troubleshooting: I downloaded the electron-api-demos repository to see if electron worked in that project
Result: electron-api-demos works perfectly as expected
Troubleshooting: I downgraded my electron version from "^6.0.3" to "^6.0.1", which works on a different project on my computer
Result: problem persists
Troubleshooting: I created a new empty Git branch, with no code and attempted to create a new minimal electron project in the same git repository I had been seeing the problem in
Result: problem re-emerges
Troubleshooting: Completely re-installed Node JS, changing versions from 12.x latest to 10.x LTS
Result: no change
Troubleshooting: cloned and attempted to run the project inside an Ubuntu Virtual Machine
Result: Success, project works as expected
Troubleshooting: Asked Co-worker to install project on their Windows 10 machine
Result: Success, co-worker could not re-produce my issue
Code
I set up an extremely minimal project to re-produce this issue. The following is my current project:
package.json
{
...
"main": "main.js",
"scripts": {
"electron-start": "electron ."
},
"devDependencies": {
"electron": "^6.0.3"
},
...
}
main.js
const {app, BrowserWindow} = require('electron')
function createWindow () {
console.log("inside the on ready callback"); //for troubleshooting
win = new BrowserWindow({width: 800, height: 600})
win.loadFile('index.html')
}
console.log("outside the function"); //for troubleshooting
app.on('ready', createWindow)
index.html
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Hello World!</h1>
</body>
</html>
When I run yarn electron-start, the following prints out to my console:
yarn run v1.17.3
$ electron .
outside the function
The print statement for inside the on ready callback is never reached. No errors are being emitted.
Conclusion
At this point, my suspicion is that there is something on my computer that is messed up. The Git repository that this code runs inside seems to be causing problems as well. I've done a lot of googling and I can't find anyone else facing this problem. The only thing I can think from here is to try scrapping our entire git repository and creating a new one (which may or may not be possible), and taking my computer into tech support for a possible replacement. Any clues on how to move forward would be greatly appreciated. Thanks
Alright, so I eventually did find a solution to this. This error was caused by attempting to install extra devtools using electron-devtools-installer. I found that the error was caused by data being left over in the %AppData%/electron directory, and the %AppData%/[projectname] directory. Deleting these two directories solves this issue.
Workaround: Call app.removeAllListeners('ready') before app.on('ready', createWindow)

Strange ECONNRESET error I cannot figure out

I do not know, if this is related to koa, or is problem of some other npm module or something else. I am going to start from here.
So to the problem. I am having REST api written in koa v1. We are running node server in the Docker image. One of the endpoints we have, starts the import and returns the status 200 with message: "import started", and when the import finishes, we send Slack message to notify us.
So first I tested the server on my local machine, everything works (endpoint does not throw any errors). Then I built docker image. I run container localy, everything works (endpoint does not throw any errors). I deploy my image to Mesos environment, everything works so far. Container runs, every endpoint works, beside import endpoint. When I call it, after few seconds (5 to 10), I get ECONNRESET error, the running container gets killed and new running instance is started. So import is terminated.
At the beginning we assigned 128 MB ram to the docker container and that seems to be enough. After import error occurred, we thought maybe OOM killed process. So we decided to check dmesg and we could not find any log entries related to the OOM and the process of the running container. Then we checked ram usage of the container locally (with htop) and found out it uses aprox. 250+ MB, so we decided to add more ram in marathon config (512 MB). That however did not help, same error occurred.
Because the error was not explicit enough we installed longjohn module, so we could get more detailed error message. That got us just a little bit more information, but not as much as we thought it would.
Error: read ECONNRESET
at exports._errnoException (util.js:1026:11)
at TCP.onread (net.js:569:26)
---------------------------------------------
at Application.app.callback (/src/node_modules/koa/lib/application.js:130:45)
at Application.app.listen (/src/node_modules/koa/lib/application.js:73:39)
at Promise.then.result (/src/server.js:97:13)
Error: read ECONNRESET
at exports._errnoException (util.js:1026:11)
at TCP.onread (net.js:569:26)
Line 97 of the server.js is:
96:if(!module.parent) {
97: app.listen(port, (err) => {
98: if (err) {
99: console.error('Server error', err);
100: }
101: console.log('Listening on the port', port);
102: });
103:}
So what exactly happens in the endpoint logic. We are using postgres npm module pg. We are passing pg.Pool to the context, so later we can use it in our models. We are executing insert query encapsulated in promise and push promises in the array. There are roughly 2700+ records. Later we do Promise.all on the array of promises and with then we send the message to Slack.
As you can see I do not know if the error is related to koa or pg or some other thing. What is more intriguing is that locally everything works (node server as well as in docker container), but on Mesos it does not. How can I find out what is wrong?
version of koa npm module: 1.2.0
version of pg npm module: 6.1.0
version of Postgres 9.5
version of Mesos: 1.0.1
According to this github issue this is an error caused by tiny-lr.
It seems that downgrading to version 0.2.1 stops it, but this is usually a dependency of other packages you're using that you've got no control over. You might be able to filter out the error by displaying all errors except this, as such:
if (error.code !== 'ECONNRESET') { console.log(error) }
The issue is still open, and dates from Oct 27, 2016. Don't know if it will get fixed or not. But as far as feedback goes, it doesn't seem like a dangerous error, or to have any impact whatsoever. But heh, I'd rather fix mine too, if there was a way.
Thanks to another developer, we found out what was the cause of the ERROR. We used all connections in the pool when there was an import running.
When the marathon was requesting the service status at the time of the import, service tried to connect to the database to test the connection and at that time the connection to the database was terminated. Service became unhealthy and marathon restarted the service. We re-factored the import code. We are limiting the number of pool connections.

NodeJS: forever.js throws binding error : EROFS read only file system

Okay, so I am using nodejitsu's forever(v0.11.1) module to keep my NodeJS(v0.10.28) + expressJS(3.5.1) server running on VPS(CentOS-6.4). Everything was working smoothly untill recently when I started getting following error while running command: forever start server.js As soon as I run this command I got the following error:
I tried to see the file: ls - l /root/.forever/tVYM.log, No such file was found
When I tried to start my node server using pm2, I got the following error:
I don't understand why is this happening even if I am root(su) user. Also, if I try to edit my server.js file, CentOS won't let me edit file and warns me about insufficient privilege.
But when I rebooted VPS and used forever, things were okay again but after some time, my server went down again and when I used forever to run my node app, forever threw the same error. I just can not see reason behind this. Thanks in advance

Resources