Fix socket closing race.