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.