Make detection of closed connections more robust.