socket.io server does not terminate tcp connection when client disconnects due to a network error - node.js

I am running a nodejs server and using socket.io 1.3.5 for handling websocket connections. When server receive a socket disconnect event with "ping timeout" or "transport close", it disconnects the socket but do not clear all the binding. It prints the below log
socket.io:client client close with reason ping timeout
socket.io:socket closing socket - reason ping timeout
socket.io:client ignoring remove for WX-M8GL6SvkQtxXMAAAA
The strange thing I have noticed when socket disconnects due to some network error, the tcp socket binding from server to browser is not cleared and remains in ESTABLISHED state forever. I can see the the below mentioned connection even after 12 hrs of receiving disconnect due to ping timeout.
node 29881 user 14u IPv4 38563924 0t0 TCP 10.5.7.33:5100->10.5.6.50:49649 (ESTABLISHED)
node 29881 user 15u IPv4 38563929 0t0 TCP 10.5.7.33:5100->10.5.6.50:49653 (ESTABLISHED)
node 29881 user 16u IPv4 38563937 0t0 TCP 10.5.7.33:5100->10.5.6.60:49659 (ESTABLISHED)
What can I do to remove the stale connections on socket disconnect events ?

I found the solution! According to this issue, there is a bug in SocketIO which is fixed in version 1.4.x:
https://github.com/socketio/socket.io/issues/2118
I have upgraded to v1.4.5 and the TCP connections are now correctly closed after the SocketIO connection closes.

Related

DigitalOcean Network Firewall allowing SSH connections on ports other than only 22

I have a droplet on DigitalOcean with IPv4 and IPv6 enabled. The droplet is behind a digital ocean network firewall with the following rules:
Inbound:
SSH TCP 22 All IPv4, All IPv6
HTTP TCP 80 All IPv4, All IPv6
HTTP TCP 443 All IPv4, All IPv6
Outbound:
ICMP ICMP All IPv4 All IPv6
All TCP TCP All ports All IPv4 All IPv6
All UDP UDP All ports All IPv4
My understanding and expectation is that will block all ssh attempts on ports other than port 22. However when checking the sshd unit in systemd journal. I see the following entries:
2022-12-29 03:00:32 Disconnected from invalid user antonio 43.153.179.44 port 45614 [preauth]
2022-12-29 03:00:32 Received disconnect from 43.153.179.44 port 45614:11: Bye Bye [preauth]
2022-12-29 03:00:31 Invalid user antonio from 43.153.179.44 port 45614
2022-12-29 02:58:37 Disconnected from invalid user desliga 190.129.122.3 port 1199 [preauth]
2022-12-29 02:58:37 Received disconnect from 190.129.122.3 port 1199:11: Bye Bye [preauth]
2022-12-29 02:58:37 Invalid user desliga from 190.129.122.3 port 1199
and many more of these lines, which means the firewall is not blocking ssh connections on ports other than 22.
The following graph shows the number of ssh connections to ports other than 22 in the last hour. The connections are reduced with enabling the Network Filter, but they not diminished.
Could it be that the Network Firewall of DigitalOcean is broken?
What am I missing?
Anyone is seeing the same situation on their infrastructure?
The ports being shown in the log are the remote ports that the connections are coming from on the remote IPs, and not indicating that those ports are listening on your server or through the firewall. The firewall is configured from your description to allow for any remote IP and port to connect to your droplet on local ports 22, 80, and 443.

Unable to connect to local host from 127.0.0.1, localhost and not even with my public ip

I have my Windows server 2012 which is active on production and running 2 websites of .NET. Now I want to run my wordpress site I had configured everything and my wordpress site was working fine before but all of sudden now am unable to connect to local host and even wp admin dashboard is not appearing so I deleted all that stuff uninstalled MYSQL connector MYSQL and web platform installer too. Even now I'm facing the same problem.
Whenever I try to connect 127.0.0.1 /Localhost I get the same message for both "This site can't be
reached" and if I try to connect with my public ip it says "HTTP Error 404. The requested resource is not found."
My netstat results are mentioned below:
C:\Users\Administrator>netsh http show iplisten
IP addresses present in the IP listen list:
173.208.205.34
173.208.205.35
173.208.205.36
C:\Users\Administrator>netstat -ano
Active Connections
1. Proto Local Address Foreign Address State
PID TCP 0.0.0.0:135 0.0.0.0:0
LISTENING
1192 TCP 0.0.0.0:180 0.0.0.0:0
LISTENING 1388 TCP 0.0.0.0:445 0.0.0.0:0
LISTENING 4 TCP 0.0.0.0:1433 0.0.0.0:0
LISTENING 2812 TCP 0.0.0.0:1443 0.0.0.0:0
LISTENING 1388 TCP 173.208.205.34:80 0.0.0.0:0
LISTENING 4 TCP 173.208.205.34:139 0.0.0.0:0
LISTENING 4 TCP 173.208.205.34:443 0.0.0.0:0
LISTENING 4 TCP 173.208.205.34:443
160.153.147.141:35160 TIME_WAIT 0
TCP 173.208.205.34:1433 122.176.28.110:2048 ESTABLISHED 28
Additionally, I have checked the etc/hosts file it have 127.0.0.1 localhost uncommented there.
I have also disabled the firewall that make no change.
Can anyone tell what is wrong with this ?
I notice that there is no 0.0.0.0:80 in the IP listen list. Does your site bind to localhost:80?
The correct IP address in list should include
0.0.0.0:80 (ipv4) and [::]:80 (ipv6)
I think you can add 127.0.0.1 to IP listen list.
netsh http add iplisten ipaddress=127.0.0.1
Then check whether it is in list.

Can Memory leaks cause getaddrinfo EMFILE

I'm having some trouble with my NodeJS API.
Sometimes, it returns, ConnectionError: getaddrinfo EMFILE and is all is fuc** after this.
So, I've started to investigate. I found it would be caused by the "to many files descriptors open". We can apparently increase the number of open files that are authorized but it would not definitely fix the problem.
I found in this article, that we can increase the file descriptors settings and the ulimit. But what is the difference?
Then, to try to isolate my problem, I've run the lsof -i -n -P | grep nodejs command. Indeed, the number of connections established is increasing, so I imagine I have somewhere in my code some connections that are not closed.
I have some fs.readFileSync and fs.readDirSync etc… but I have not set the autoClose:true. Did you think it would be that?
Do you have any ideas or advice?
PS : the App run on a Ubuntu machine
EDIT , 16-02-2016
I have ran this command on my production machine lsof -i -n -P | grep nodejs
What I see is something like this:
...
nodejs 27596 root 631u IPv4 109781565 0t0 TCP 127.0.0.1:45268->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 632u IPv4 109782317 0t0 TCP 172.31.58.93:4242->172.31.55.229:61616 (ESTABLISHED)
nodejs 27596 root 633u IPv4 109779882 0t0 TCP 127.0.0.1:45174->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 634u IPv4 109779884 0t0 TCP 127.0.0.1:45175->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 635u IPv4 109781569 0t0 TCP 127.0.0.1:45269->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 636u IPv4 109781571 0t0 TCP 127.0.0.1:45270->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 637u IPv4 109782319 0t0 TCP 127.0.0.1:45293->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 642u IPv4 109781790 0t0 TCP 127.0.0.1:45283->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 643u IPv4 109781794 0t0 TCP 127.0.0.1:45284->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 644u IPv4 109781796 0t0 TCP 127.0.0.1:45285->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 645u IPv4 109781798 0t0 TCP 172.31.58.93:4242->172.31.55.229:61602 (ESTABLISHED)
nodejs 27596 root 646u IPv4 109781800 0t0 TCP 127.0.0.1:45286->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 647u IPv4 109781802 0t0 TCP 172.31.58.93:4242->172.31.0.198:1527 (ESTABLISHED)
nodejs 27596 root 648u IPv4 109781804 0t0 TCP 127.0.0.1:45287->127.0.0.1:7272 (ESTABLISHED)
nodejs 27596 root 649u IPv4 109781806 0t0 TCP 127.0.0.1:45288->127.0.0.1:7272 (ESTABLISHED)
But I don't know what it means, do you have any ideas about this?
Thanks a lot.
So I thought I found out what is going on!
I use Redis & Redis session npm modules for my cart storage, but when I created, updated, I created a connection to Redis, each time, before using it.
var session = new Sessions({ port : conf.redisPort, host : conf.redisHost});
session.get({
app : rsapp,
token : this.sessionToken },
function(err, resp) {
// here some workin'
})
Now I just created the connection when my app starts and store this as a singleton and use whenever I want.
// At the start of the App
var NS = {
sessions : new RedisSessions({port: config.redisPort, host: config.redisHost}),
};
// Later somewhere in the app
NS.session.get({
app : rsapp,
token : this.sessionToken },
function(err, resp) {
// here some workin'
})
It was pretty obvious but now I found it… If it can help someone, I'll mark this one as solved.

HAProxy cannot bind to socket 1883

I am trying to bind a HaProxy on a Fedora 21 instance to socket 1883 (for the MQTT protocol).
I get
[ALERT] 215/130943 (926) : Starting proxy mqtt: cannot bind socket [0.0.0.0:1883]
There does not seem to be anything listening on this port as long as I could check. Does anyone have an idea about what might be the problem?

nodejs socket.io socket file not close after disconnect

I'm using node(v.0.12.4), socket.io(1.3.5) which is server.
Server is Ubuntu 14.04 LTS.
Client is android using socket.io library which is compatibility socket.io 1.X.X (https://github.com/nkzawa/socket.io-client.java)
I have a question.
I run socket.io server(3305 port) and show list of file(lsof -i | grep 3305)
**COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME**
**node 135665 root 11u IPv6 516450 0t0 TCP *:3305(LISTEN)**
and client connect to socket.io server and show list of file(lsof -i | grep 3305)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 135665 root 11u IPv6 516450 0t0 TCP *:3305(LISTEN)
node 135665 root 14u IPv6 516450 0t0 TCP *:ServerIP(xxx.xxx.xxx.xxx:3305)->AndroidIP(xxx.xxx.xxx.xxx:33972)(ESTABLISHED)
and android's network is changed, such as wifi to lte.
socket.io server disconnect android client because of pingTimeout(60sec). and show list of file(lsof -i | grep 3305)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 135665 root 11u IPv6 516450 0t0 TCP *:3305(LISTEN)
node 135665 root 14u IPv6 516450 0t0 TCP *:ServerIP(xxx.xxx.xxx.xxx:3305)->AndroidIP(xxx.xxx.xxx.xxx:33972)(ESTABLISHED)
socket.io server source is
var io=new Server(3305);
io.sockets.on("connection",function(socket){
console.log("connection : "+socket.id);
socket.on("disconnect",function(){
console.log("disconnect : "+socket.id);
});
});
I show that socket.io server disconnect client. why does it remain ESTABLISHED?
Try this
var io = new Server(3305);
io.on("connection", function(socket) {
console.log("connection : " + socket.id);
socket.on("disconnect", function() {
console.log("disconnect : "+ socket.id);
});
});

Resources