node-routeros icon indicating copy to clipboard operation
node-routeros copied to clipboard

App Crashed with Timed out after 10 seconds'

Open jocasousa opened this issue 4 years ago • 11 comments

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. Server js

Error App Crash Error

jocasousa avatar Apr 28 '20 14:04 jocasousa

A workaround for now would be to append some random string after the name.

aluisiora avatar Apr 28 '20 18:04 aluisiora

Resolved. After the name error the connection was open, I forced a disconnection and a new connection.

thank you!

jocasousa avatar Apr 28 '20 22:04 jocasousa

@jocasousa can you please share your code for reference!!

melsonmascarenhas avatar May 19 '20 02:05 melsonmascarenhas

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' ```

melsonmascarenhas avatar May 19 '20 02:05 melsonmascarenhas

@jocasousa can you please share your code for reference!! Screenshot_1

:)

jocasousa avatar May 19 '20 13:05 jocasousa

Thank you ...Now my code is working. in your code your setting address by using parameters.that's great.....

melsonmascarenhas avatar May 21 '20 02:05 melsonmascarenhas

@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 avatar May 23 '20 16:05 aluisiora

@aluisiora RosException.

jocasousa avatar May 28 '20 13:05 jocasousa

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.

aluisiora avatar Jun 02 '20 17:06 aluisiora

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);
            });
        });

xeleniumz avatar Nov 28 '20 01:11 xeleniumz

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

renomureza avatar Mar 10 '21 11:03 renomureza