Fix socket closing.