1

I'm working on an RCON utility and trying to use Node.js but I'm stuck with the FIN_WAIT2 issue when closing the socket or even just ending the client. The server is a game server and I've got no access to that source other than RCON configuration there. Different production RCON clients work fine against the server, so it should be configured correctly.

How do we properly shutdown, close, destroy or whatever a socket connection in Node.js? I cannot believe I'm stuck on such a simple notion. I've found a lot of old web posts about the issue in Node.js and there is this link from a while back

Even a simple test including a suggestion there

const net = require('net');
mySock = net.connect({
  host : '127.0.0.1',
  port: 21214,
});

mySock.close = function(data) {
    var Self = this;
    if (data) this.write(data, function() {
        Self.destroy();
      } );
    else this.destroy();
};

setTimeout(f1, 1000);

function f1 () {
  //  mySock.destroy();
  //  mySock.end();
  mySock.close();
}

Results in connections left in FIN_WAIT2 status. Forever it seems. Eventually the FIN_WAIT2 goes away but it leaves the game server in some kind of odd state that new connections from other different production RCON apps will not work until the server is restarted


tcp        1      0 127.0.0.1:21214         127.0.0.1:35560         CLOSE_WAIT  5724/GameServer
tcp        0      0 127.0.0.1:35560         127.0.0.1:21214         FIN_WAIT2   -

I dunno what I need to do for Node.js to cleanly close this down. If I use another RCON library based purely on C, like this, I never get an issue and as soon as the command is done, there are no lingering netstat connections. That is of course unless I first run my Node.js test program. In that case, the C RCON will not connect until the server is restarted.

GenerationTech
  • 79
  • 1
  • 11
  • The problem is that the *peer* hasn't closed its end yet. Nothing to do with this end. – user207421 Dec 24 '19 at 00:13
  • BOTH ends show a fragment of the connection open. When I run the C RCON tool, there is absolutely no remaining netstat fragment, so it is possible to have an RCON connection to this game server come-and-go without leaving stuff open. I cannot see how to do this in Node.js and find repeated mentions of this problem without solution. Most of it is years back so I guess people just stopped asking for help and either switched language or are using exotic timers on the TCP stack to overcome this issue – GenerationTech Dec 24 '19 at 00:25
  • It is impossible for both ends to show FIN-WAIT-2 for the same connection. CLOSE-WAIT indicates that the local application hasn't closed the socket. – user207421 Dec 24 '19 at 00:56
  • Yeah I get that. Only one side shows FIN_WAIT2. I don't know how to close a socket in Node.js so it doesn't do that. And it appears no one does either, which makes no sense. Even the examples in the docs do this – GenerationTech Dec 24 '19 at 02:26

0 Answers0