I think what is happening is that between storing the connections as an array and then removing them, if a connection closes, the ‘remove’ command runs against a connection which doesn’t exist, which results in the error.
I’ve tried adding an ‘on-error={’ condition to this, but I can’t get it to work, I always get syntax errors.
Can anyone tell me a way that I can either prevent this error from occurring, or handle the error gracefully?
Sorry, I’m not sure what the result of this would be? Could you explain a bit more?
Thanks, that would work to begin with, however long-term I am wanting the script to only clear certain connections (in this case, for VoIP phones) so I need to be able to pick which connections I clear.
Sure, there can be timing issues with a lot of connections in the table. But if just want to drop some SIP connections (that was the use case for original poster I think) this could still work as expected with the correct filtering:
/ip/firewall/connection/remove [ find where protocol=udp dst-address~":5060\$" ];
I don’t see any advantage in your own solution, especially from one who cannot read and understand,
and then the “if (true) do={” doesn’t make a good impression to leave pieces thrown there at random…
and then on-horror-resume-next never bodes well..