Trying to circumvent random 'endpoint not connected' errors during shutdown