Dynamic DHCP Client Advanced Script - sometimes produces duplicate entries

I have dual dynamic WAN setup with failover and PCC load balancing. I have pretty identical DHCP Client scripts to establish routes, however, with one script it duplicates the entries 3x and I’m not sure why. There is no problem working right now. I am on 7.15.1. Here are my scripts for WAN1 and WAN2. WAN1 creates each entry duplicated 3x in Routes, WAN2 has individual Route entries as expected. Has anyone had this problem with scripted route entries being duplicated? Is it a bug or scripting error? Thanks!

WAN1 DCHP Client Script:

:if ($bound) do={

/ip route add dst-address=1.1.1.1 scope=10 gateway=$"gateway-address" comment="WAN1"
/ip route add dst-address=0.0.0.0/0 distance=1 gateway=1.1.1.1 target-scope=11 check-gateway=ping comment="WAN1"
/ip route add dst-address=0.0.0.0/0 distance=1 gateway=1.1.1.1 target-scope=11 check-gateway=ping routing-table=WAN1 comment="WAN1"
} else={

/ip route remove [/ip route find comment="WAN1"]

}

WAN2 DHCP Client Script:

:if ($bound) do={

/ip route add dst-address=4.2.2.1 scope=10 gateway=$"gateway-address" comment="WAN2"
/ip route add dst-address=0.0.0.0/0 distance=2 gateway=4.2.2.1 target-scope=11 check-gateway=ping comment="WAN2"
/ip route add dst-address=0.0.0.0/0 distance=1 gateway=4.2.2.1 target-scope=11 check-gateway=ping routing-table=WAN2 comment="WAN2"
/ip route add dst-address=192.168.225.1 distance=1 gateway=$"gateway-address" comment="WAN2"
} else={

/ip route remove [/ip route find comment="WAN2"]

}

DuplicatedRoutes.jpg

Maybe the script is running 3x?

Only as an experiment, what happens with:

:if ($bound) do={
/ip route remove [/ip route find comment="WAN1"]
delay 3s
/ip route add dst-address=1.1.1.1 scope=10 gateway=$"gateway-address" comment="WAN1"
/ip route add dst-address=0.0.0.0/0 distance=1 gateway=1.1.1.1 target-scope=11 check-gateway=ping comment="WAN1"
/ip route add dst-address=0.0.0.0/0 distance=1 gateway=1.1.1.1 target-scope=11 check-gateway=ping routing-table=WAN1 comment="WAN1"
} else={

/ip route remove [/ip route find comment="WAN1"]

}

My thought as well, strangely the updated script (as you suggested) results in the exact same 3x duplicated routes.

HMMM.
Since with the changes the script is (should be) deleting the entries every time it is run, it is a logical impossibility:

  1. all entries with “WAN1” are deleted
  2. three new entries are created
    you can run the script 1, 2, 3 or 42 times, the result should always be the three new entries (and only three).
    So, not only the script (for whatever reasons) is run three times, but the deletion of the routes is not effective, so there must be something wrong also in:
    /ip route remove [/ip route find comment=“WAN1”]
    maybe:
    /ip route remove [find comment=“WAN1”]

Or try post-processing, deduplicating them:;
http://forum.mikrotik.com/t/deleting-routes-script/149326/1

The examination of the condition should be improved. The bound variable contains a string value (“0” or “1”).

:if ($bound = "1") do={...}