fix bug when connection is closing