Node.js http server crashes with unknown IP address displayed - node.js

I am running a Node.js HTTP server, and suddenly the following message is displayed, and the server crashes:
UPDATED ERROR LOG: (after edit)
Uncaught exception in main server
{ Error: connect ETIMEDOUT 139.99.8.126:80
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '139.99.8.126',
port: 80 }
Uncaught exception in main server
{ Error: socket hang up
at createHangUpError (_http_client.js:253:15)
at Socket.socketCloseListener (_http_client.js:285:23)
at emitOne (events.js:101:20)
at Socket.emit (events.js:188:7)
at TCP._handle.close [as _onclose] (net.js:497:12) code: 'ECONNRESET' }
This is a foreign IP address not used by us.
I tried to grep into all node modules for this IP address and see nothing.
Appears to be a hacking attempt but I have no clue where to start looking.
Any help will be appreciated. I have blocked the IP address in the firewall.

As per node.js docs about errors say:
ETIMEDOUT (Operation timed out): A connect or send request failed because the connected party did not properly respond after a period of time. Usually encountered by http or net — often a sign that a socket.end() was not properly called.
You should create a handler for errors, so your server won't crash:
netSv.on('error', function (error) {
if( error.message.code === 'ETIMEDOUT' ){
// mail the error with some additional data to you or do something with it
}
})

Related

How can I trace back "EPROTONOSUPPORT: protocol not supported :::3000" in node.js?

I am more than clueless at the moment. I am trying to start a keystonejs-6 app in production mode and the the app throws this error:
Starting Keystone
node:events:505
throw er; // Unhandled 'error' event
^
Error: listen EPROTONOSUPPORT: protocol not supported :::3000
at Server.setupListenHandle [as _listen2] (node:net:1355:21)
at listenInCluster (node:net:1420:12)
at doListen (node:net:1559:7)
at processTicksAndRejections (node:internal/process/task_queues:84:21)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1399:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EPROTONOSUPPORT',
errno: -43,
syscall: 'listen',
address: '::',
port: 3000
}
I have no way to trace back, at which point of the keystonejs application code the error originated. As it seems, keystonejs provides practically no logging on the application code itself.
Is there a way to find out, what kind of protocol is meant by this error message?

Memcached refuse connection after node upgrade to v18.7.0

I am using memcached locally to store user sessions.
To work with memcached I use the npmjs.com/package/memcached
After upgrading nodes to version v18.7.0, the server stopped connecting to memcached at localhost:11211
However, when the address is changed to 127.0.0.1:11211, the connection proceeds normally, but an error still occurs during further work:
Error: connect ECONNREFUSED ::1:11211
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16) {
[stack]: 'Error: connect ECONNREFUSED ::1:11211\n' +
' at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16)',
[message]: 'connect ECONNREFUSED ::1:11211',
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 11211
}
What could be causing this and how to fix it?
The problem was that memcached was configured to accept connections only via IPv4.
After adding in the settings for receiving connections via IPv6, everything worked.

aws-serverless-express connection error - socket hangup

I have a lambda function accessed via API gateway. The function receives username and password and performs authentication on a given active directory.
If the user is found then it calls the database to fetch the user by username > generates JWT and returns it in the response.
For last few days I have been getting CORS errors on the login page. On further inspection of the CloudWatch logs I see these errors
{
"errno": "ETIMEDOUT",
"code": "ETIMEDOUT",
"syscall": "connect",
"address": "10.1.2.39",
"port": 389
}
error.code Error: connect ETIMEDOUT 10.1.2.39:389
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)
{ errno: 'ETIMEDOUT', code: 'ETIMEDOUT', syscall: 'connect', address: '10.1.2.39', port: 389}
ERROR: aws-serverless-express connection error
ERROR Error: socket hang up
at connResetException (internal/errors.js:609:14)
at Socket.socketOnEnd (_http_client.js:458:23)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) { code: 'ECONNRESET'}
The weird thing is, when I try to log into the application for the first time, I get these errors, but let's say I wait for some 15-20 minutes and then try logging again, no error appears and I am logged in smoothly.
The AD is maintained by the customer and they claim nothing is wrong on their end. This issue started happening recently even though the application has been in production for the last six months.
I am using the activedirectory module for AD authentication. If I run a simple authenticate code locally with the same username and password then it works so there is no problem with AD authentication or the credentials.
I am using Node 12 in my lambda. Also I am using aws-serverless-koa and not express so I am assuming that the error is coming from some dependency (probably activedirectory).

Redis ETIMOUT... How many reasons will cause this?

I'm running Redis on Linux and for a period of time an error occured below in the log:
{ Error: Redis connection to xxx.yyy.zzz.ttt:6379 failed - connect ETIMEDOUT xxx.yyy.zzz.ttt:6379
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: 'xxx.yyy.zzz.ttt',
port: 6379 }
I checked username and password, it seems everything goes right with me.
I wanna know roughly:
1) How many reasons will cause this?
2) What suggestions do you have to fix that?

Twitter Stream & Node js server Error

I am trying to connect connect to twitter streaming api and I am getting the error
events.js:87
throw er; // Unhandled 'error' event
^
Error: Bad Twitter streaming request: 401
at ClientRequest.<anonymous> (/home/vikas/t4d/node_modules/twit/lib/oarequest.js:202:19)
at ClientRequest.g (events.js:201:16)
at ClientRequest.emit (events.js:109:17)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:421:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:113:23)
at TLSSocket.socketOnData (_http_client.js:312:20)
at TLSSocket.emit (events.js:109:17)
at readableAddChunk (_stream_readable.js:164:16)
at TLSSocket.Readable.push (_stream_readable.js:128:10)
at TCP.onread (net.js:540:20)
THe official api says it as Unauthorized access, but I am sure I have the right credentials (I have tested them before).
Also my www file has the entry
nconf.defaults({
'PORT': process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 3000,
'BIND_IP': process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'
});
where putting 127.0.0.1 is also fine. I don't understand why I am getting the error and how to remove it ?
I am using the code for connecting from here. I have all the dependencies installed.
Thanks a lot for your help.
I patched this with updating the system time, it was delayed with 5 minutes. Since the date time is OK, the request is successful.

Resources