How to chek if an agent is unable to reach his destination for quite some time to disable the movement?

Let’s imagine that a unit started moving to some destination but it was completely blocked while he was moving towards it so I do not want it to hit walls forever, but to realize that his task is over and stop.
And also if two or more units are trying to reach the same destination at the same time, they will just push each other forever both unable to reach it, so I want them to also realize it and stop.
I unserstand that I can remove the destinationSetter.target in my script, but how to catch this exact conditions when I should do it?