If an error occurs during the connection of the socket then no close event is sent which means this.socket is not cleared and connect() errors out with "Already connected or connecting" when called a second time. See code below for reproduction.
Rcon = require("rcon-client").Rcon;
async function bug() {
let client = new Rcon({
host: "localhost",
port: 1234,
password: "blah",
});
client.on("error", () => { /* ignore */ });
try {
await client.connect();
} catch (err) {
console.log("first error:", err.message);
}
try {
await client.connect();
} catch (err) {
console.log("second error:", err.message);
}
}
bug().catch(console.log);
// Expected output
// first error: connect ECONNREFUSED 127.0.0.1:1234
// second error: connect ECONNREFUSED 127.0.0.1:1234
// Actual output
// first error: connect ECONNREFUSED 127.0.0.1:1234
// second error: Already connected or connecting
If an error occurs during the connection of the socket then no
close
event is sent which meansthis.socket
is not cleared andconnect()
errors out with "Already connected or connecting" when called a second time. See code below for reproduction.