handle closed connections gracefully