fixed potential crash when closing connection