From 23f6d449e0f6bcf9846dbc57b652f129db7e133d Mon Sep 17 00:00:00 2001 From: Jose Garcia Date: Mon, 20 Sep 2021 21:16:54 +0000 Subject: [PATCH] Close RPC conn only - Only close SSH if RPC fails. Closing RPC automatically closes the underlying stream which in this case is the SSH connection. - I thought about closing the SSH conn instead of RPC, but there is a bit more cleanup that the RPC library needs to do. --- session.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/session.go b/session.go index 5ea961d82..5202205a8 100644 --- a/session.go +++ b/session.go @@ -15,16 +15,14 @@ type Session struct { // Close should be called by users to clean up RPC and SSH resources whenever the session // is no longer active. func (s *Session) Close() error { - if err := s.rpc.Close(); err != nil { + // Closing the RPC conn closes the underlying stream (SSH) + // So we only need to close once + err := s.rpc.Close() + if err != nil { s.ssh.Close() // close SSH and ignore error - return fmt.Errorf("failed to close RPC conn: %w", err) } - if err := s.ssh.Close(); err != nil { - return fmt.Errorf("failed to close SSH conn: %w", err) - } - - return nil + return err } // Port describes a port exposed by the container.