Skip to content

Commit c55660e

Browse files
committed
[mikrotik-sdwan] fix wan address reslolving after failed route
1 parent 7b39c89 commit c55660e

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/modules/mikrotik-sdwan/container/workers/tasks/wanaddress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = async ({ routerOsApi, mongoSingle, wanAddressesCollection }) =>
4242
logger.debug(`fetch: from ${address} via bridge ${route._bridgeName}`);
4343

4444
// do the fetch
45-
const data = await routerOsApi.run("/tool/fetch", [
45+
const data = await routerOsApi.conn.write("/tool/fetch", [
4646
`=src-address=${address}`,
4747
`=url=https://ifconfig.me/ip`,
4848
`=mode=https`,

src/modules/mikrotik-sdwan/container/workers/worker-wanaddress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const main = async () => {
4646

4747
workerTaskManager({
4848
tasks: [
49-
{ name: "wanaddress", seconds: 30 },
49+
{ name: "wanaddress", seconds: 30, delay: 10 },
5050
], context: { routerOsApi, mongoSingle, wanAddressesCollection }, baseDir: __dirname
5151
});
5252

src/server/core/routeros-api.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ class RouterOSApi {
8686

8787
async run(command, params = {}) {
8888
// queue commands so RouterOS API never overlaps
89+
// use .catch(() => {}) to prevent a failed command from poisoning the queue
90+
// and blocking all subsequent commands
8991
logger.debug(`routeros-api: queueing command ${command} with params ${JSON.stringify(params)} for ${this.host}`);
90-
this._queue = this._queue.then(() => this._execute(command, params));
91-
return this._queue;
92+
const next = this._queue.catch(() => { }).then(() => this._execute(command, params));
93+
this._queue = next;
94+
return next;
9295
}
9396

9497
async _execute(command, params) {

0 commit comments

Comments
 (0)