node-routeros
node-routeros copied to clipboard
App Crashed with Timed out after 10 seconds'
Hello I have a problem with adding a queue.
If I add a queue record that already has a name, mikrotik rejects this request, of course.
The problem is that my node-routeros server crashes with the following error. "failure: already have such name"
name: 'RosException', errno: 'SOCKTMOUT', message: 'Timed out after 10 seconds'
Is it possible to just get the error message and the server doesn't shut down?
Code BackEnd.
Error App Crash
A workaround for now would be to append some random string after the name.
Resolved. After the name error the connection was open, I forced a disconnection and a new connection.
thank you!
@jocasousa can you please share your code for reference!!
I'm getting this error when i run example code
at Connector.onTimeout (D:\mikrotik\node_modules\node-routeros\dist\connector\Connector.js:187:30)
at Object.onceWrapper (events.js:416:28)
at Socket.emit (events.js:310:20)
at Socket._onTimeout (net.js:479:8)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
name: 'RosException',
errno: 'SOCKTMOUT',
message: 'Timed out after 10 seconds' ```
@jocasousa can you please share your code for reference!!
:)
Thank you ...Now my code is working. in your code your setting address by using parameters.that's great.....
@jocasousa if you listen for error on the connection object, what info does it give?
Example:
conn.on('error', (err) => {
console.log(err);
});
conn.connect()[...]
@aluisiora RosException.
Seems like the error is bubbling up to the connection socket object, which shouldn't happen. I'm not having a free time lately to make a sample code to replicate this, so it might take some time to fix.
after I spent my time to test this error. I found the solution you can use promise way to work around this problem , here is my example code.
let conn = new RouterOSAPI ({
host: '10.0.0.1',
user: 'admin',
password: 'password',
});
return new Promise(async (resolve,reject) => {
conn.connect()
.then(() => {
conn.write("/interface/print").then((data) => {
// Got the interfaces
conn.close();
resolve(data);
}).catch((err) => {
// Got error trying to print the interfaces
console.log(err);
reject(err);
});
}).catch((err) => {
// Got an error while trying to connect
console.log(err);
reject(err);
});
});
private onTimeout(): void {
this.destroy();
this.emit(
'timeout',
new RosException('SOCKTMOUT', { seconds: this.timeout }),
this,
);
}
Move this.destroy();
before this.emit(...)
solving this problem.
https://github.com/aluisiora/node-routeros/blob/f7d710e594e7a73f18f59901eedf8528ce40d66e/src/connector/Connector.ts#L246