Fix error on closing the client and router in case it was auto-closed before