Fix socket cleanup