Sockjs/socketio disconnect delay behind apache proxy

Viewed 1408

I need to handle users disconnecting from my sockjs application running in xhr-polling mode. When I connect to localhost, everything works as expected. When I put apache between nodejs and browser, I get ~20 sec delay between closed browser and disconnect event inside nodejs. My apache proxy config is following:

<Location />
  ProxyPass http://127.0.0.1:8080/
  ProxyPassReverse http://127.0.0.1:8080/
</Location>

The rest of the file is default, you can see it here. I tried playing with ttl=2 and timeout=2 options, but either nothing changes, or I get reconnected each 2 seconds without closing browser. How can I reduce additional disconnect timeout, introduced, but apache, somewhere in its defaults?

3 Answers

The 20 sec delay not in the apache proxy. I got the same issue, delay not happening in the local URL, but delay happening in global URL.

The issue was solved in the NodeJs itself. Need to send one time data from server to client to make sure it's initialized. This problem not in the documentation and issues blog at the WebSocket plugin.

Send a dummy message after request accepted in the server, like below.

let connection = request.accept(null, request.origin);

connection.on('message', function (evt) {
    console.log(evt);
});

connection.on('close', function (evt) {
    console.log(evt);
});

connection.send("Success"); //dummy message to the client from server
Related