enhance the connection close procedure, gracefully shutdown