TS3-NodeJS-Library
TS3-NodeJS-Library copied to clipboard
Unhandled Error ECONNRESET
Describe the bug Unhandled error due to ECONNRESET crashes my script. Already tried to catch the error with .on("error"), but the error is still unhandled and will crash my node script. The error and my connection setup are down below.
To Reproduce No direct way to reproduce, this occurs a few minutes after I established the connection (even with commands being sent).
Expected behavior No unhandled exceptions.
Versions used
- TeamSpeak Server Version: 3.13.7
- NodeJS Version (check with node -v): v20.12.0
- Library Version: 3.5.1
Additional context
node:events:496 throw er; // Unhandled 'error' event ^
Error: read ECONNRESET at TCP.onStreamRead (node:internal/stream_base_commons:217:20) at TCP.callbackTrampoline (node:internal/async_hooks:130:17) Emitted 'error' event on ProtocolRAW instance at: at ProtocolRAW.handleError (C:\Users<redacted><myProject>\node_modules\ts3-nodejs-library\lib\transport\protocols\raw.js:41:14) at Socket.emit (node:events:518:28) at emitErrorNT (node:internal/streams/destroy:169:8) at emitErrorCloseNT (node:internal/streams/destroy:128:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { errno: -4077, code: 'ECONNRESET', syscall: 'read' }
Node.js v20.12.0
And here is my connection setup:
import {
QueryProtocol,
TeamSpeak
} from "ts3-nodejs-library";
import logService from "./logger";
import config from "../config";
const logger = logService(module);
const connectionOptions: Partial<TeamSpeak.ConnectionParams> = {
host: config.ts3.host,
protocol: QueryProtocol.RAW,
queryport: config.ts3.queryPort,
serverport: config.ts3.serverport,
username: config.ts3.username,
password: config.ts3.password,
nickname: "Nickname",
keepAlive: true
};
const connectionBuilder: Promise<TeamSpeak> = (async () => {
try {
logger.info("Trying to establish TS3 Connection");
const ts3 = new TeamSpeak(connectionOptions);
await ts3.connect();
logger.info("Successfully connected to TS3");
ts3.on("close", async () => {
try {
logger.warning("disconnected, trying to reconnect...");
await ts3.reconnect(-1, 1000);
logger.warning("reconnected!");
} catch (error) {
logger.error(`Error while reconnecting to TS3: ${JSON.stringify(error)}`);
process.exit(1);
}
});
ts3.on("error", async () => {
try {
logger.warning("disconnected, trying to reconnect...");
await ts3.reconnect(-1, 1000);
logger.warning("reconnected!");
} catch (error) {
logger.error(`Error while reconnecting to TS3: ${JSON.stringify(error)}`);
process.exit(1);
}
});
return ts3;
} catch(error) {
logger.error(`Error while establishing TS3 connection: ${JSON.stringify(error)}`);
process.exit(1);
}
})();
export default connectionBuilder;
if it happens on first connect you probably do not have your error handler attached, you first need to listen to the error event and after that you should connect to the teamspeak server
so just move the
await ts3.connect();
logger.info("Successfully connected to TS3");
right before you return from the function because it waits until it has connected and after it successfully connected it will register the error event
It does not happen on the initial connect. It happens 5-10 minutes after the connection has been established. The connection initialization was successful, since I can run commands without any problem on the TS3 server. But after a while I get the error above.
Also, I moved the connect call to the bottom of my function to verify. It did not help with the unhandled error.