Fix handling socket errors.