fix close connection correctly