Ensure next write is not attempted when connection is closed.