prestonp / simple-rcon

Simple, painless node RCON client for Source servers
MIT License
14 stars 4 forks source link

Rcon commands send to factorio headless server gets duplicated causing crashes #14

Open Danielv123 opened 7 years ago

Danielv123 commented 7 years ago

I don't know what is happening, but it breaks.

I launch with the following code, which is supposed to auto reconnect,

client.on('authenticated', function () {
        console.log('Clusterio | Authenticated!');
        instanceManagement(); // start using rcons
    }).on('connected', function () {
        console.log('Clusterio | Connected!');
        // getID();
    }).on('disconnected', function () {
        console.log('Clusterio | Disconnected!');
        // now reconnect
        client.connect();
    });
prestonp commented 7 years ago

I think a timeout event should be added to gracefully recover from connection timeouts. Let me look into this and reproduce a flaky server.

skibz commented 7 years ago

the problem could be due to this. when the timeout event occurs, we call end on our side (send FIN packet to remote server)

my theory is that if we call end, is the socket destroyed or left in a state that it cannot cleanly reconnect? ie. requiring reconstruction?

i need to research/experiment with net.Socket semantics a bit to confirm my theory. will report back soon!

EDIT: also, on the note of adding a timeout event, we would do it on the same line mentioned above

skibz commented 7 years ago

so i kind of misread everything here... sorry about that.

@Danielv123 we can add an auto-reconnect option so that you don't have to use the pattern you've shown above.

the option would apply when timeout or disconnect occur, but not when calling close. then, regardless of the side from which the connection is dropped, it's just always re-established.

Danielv123 commented 7 years ago

Been looking around and we have more or less found the cause of the issue. Somehow, multiple commands get bunched up in the same packet triggering the length limit of 10k characters.

Each command sent to rcon.exec() is checked to be below 3000 characters.

I managed to capture the following package with wireshark package

You can find the start of each package by searching for lent-command. At the end of the package there is an unix timestamp, but its the same for all the commands meaning its the exact same command that the library has duplicated 4 times.

Symptoms: Rcon server dies, stops responding. No error is sent, so connection does not reset.