Fix socket exception handling