Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS + socket.io + IIS = ECONNRESET

I am running a SSL socket on port 8081. While this works perfectly with Apache2.4, after a while on IIS, socket.io crashes with ECONNRESET, which never happens with Apache. My socket.io version is 1.3.7. IIS is v10 (windows server 2016).

I've added some error handling as recommended but it does not solve the issue. Here is a sanitized code.

var options = {
  key: fs.readFileSync('example.key'),
  cert: fs.readFileSync('example.cert'),
  ca: fs.readFileSync('example.inter')
};

var app = require('https').createServer(options),
io = require('socket.io').listen(app);  
io.set('origins', '*:8081');
app.on('error', function(error){
    console.log('error', error);
});
app.listen(8081);

io.sockets.on('connection', function(__socket) {

     __socket.on('error', function(){
          __socket.destroy();
     });

     __socket.on('disconnect', function(){
          __socket.destroy();
     });
}

I read that you can fix that by adding ciphers like

ciphers: 'DES-CBC3-SHA'

but I do not know how relevant it is to my code and even where to put that!

Here is the detail of the error

{ 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' }

edit: updated to latest version (2.0.3) and still having the issue.

edit2: It appears ECONNERESET happens when using io.emit which is weird because it feels like it tries to emit without verifying that the socket is still connected first...

like image 986
Eric Avatar asked Jan 11 '18 22:01

Eric


People also ask

Why do sockets hang up?

When a socket hang up is thrown, one of two things happens: When you're a customer, When you send a request to a distant server as a client and don't get a response in a timely manner. This error is caused by the end of your socket.


2 Answers

I think that there are issues with IIS WebSockets implementations while hosting node.js applications as mentioned in an article I came across from Tomasz Janczuk - Hosting socket.io WebSocket Apps in IIS using iisnode.

There is a section about configuring IIS with a web.config file and Janczuk mentions that there is a conflict with the shipped WebSocket in IIS and node.js WebSocket implementation.

I also looked at the WebSocket setting that was introduced in IIS 8 and there have been no modifications through IIS 10.

I suggest trying to disable the IIS WebSocket setting as mentioned in Janczuks article with a web.config for IIS.

<WebSocket enabled="false"/>
like image 86
RickyM Avatar answered Sep 19 '22 00:09

RickyM


Try this

var options = {
  key: fs.readFileSync('example.key'),
  cert: fs.readFileSync('example.cert'),
  ca: fs.readFileSync('example.inter'),
  ciphers: 'DES-CBC3-SHA'
};

Reference here

like image 35
Connor Knabe Avatar answered Sep 20 '22 00:09

Connor Knabe