fix a bug when closing connection