bug fix in gate

socket may be closed by a previous event's processing.