Hello, Captain!
I can assure you that troops cannot leave your Harbor in case they were successfully secured. All actions in the game are made only after the appropriate commands which are sent by the player. This is why if your troops reach the Harbor, then they can leave it only if you recall them manually.
However, the troops can be sent into the Harbor and not reach it due to an unstable internet connection. In this case, the commend is not delivered to the game server and your troops remain in your Haven.
Unfortunately, the troops cannot be reimbursed in this case since they were lost within the regular gameplay. Please, always double check whether your troops have arrived in the Harbor before logging off the game.