Detect when socket is lost and shutdown properly.