How do you deal with failed closing request?

 
I've been doing pair trading with python on MT5. Sometimes when I close the position in a pair, one symbol was executed successfully while the other failed. Usually I wait a few minutes and run the same code again, and it would be closed successfully. But this often led to undesirable closing price. Have you encountered similar problem? How would you deal with it?
 
Add: Right now my solution is to keeping trying until the closing request is executed successfully. If it exceeds 30 seconds, it is ignored and will try again in the next loop.