diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-11 09:58:21 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-09-23 10:02:55 +0300 |
commit | 3e17670ce54496373d152f4fd054f48a4f5dbd66 (patch) | |
tree | 1dd48969bb56029e362220726c19751a881d1b65 | |
parent | 80736c54d3a24702733c6e8227e56b5067742802 (diff) |
backchannel: Propagate errors when closing server channel fails
The `close()` function we return as part of the server handshake is
responsible for closing all associated resources. In case closing any of
them fails though we never bubble up errors at all, but instead silently
succeed.
Fix this and return the first error we encounter. As we now correctly
check returned errors the errcheck linter is happy and we can drop
another exclude for the `yamux.Session` type.
-rw-r--r-- | .golangci.yml | 1 | ||||
-rw-r--r-- | internal/backchannel/server.go | 16 |
2 files changed, 12 insertions, 5 deletions
diff --git a/.golangci.yml b/.golangci.yml index a8ebf5f14..cb43b9861 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -55,7 +55,6 @@ linters-settings: # Close - (*database/sql.DB).Close - (*database/sql.Rows).Close - - (*github.com/hashicorp/yamux.Session).Close - (*gitlab.com/gitlab-org/gitaly/v15/client.Pool).Close - (*gitlab.com/gitlab-org/gitaly/v15/client.SidechannelWaiter).Close - (*gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook.SidechannelWaiter).Close diff --git a/internal/backchannel/server.go b/internal/backchannel/server.go index 9e0f0537a..9b7e58bda 100644 --- a/internal/backchannel/server.go +++ b/internal/backchannel/server.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "io" "net" "github.com/hashicorp/yamux" @@ -136,10 +137,17 @@ func (s *ServerHandshaker) Handshake(conn net.Conn, authInfo credentials.AuthInf Conn: clientToServerStream, close: func() error { s.registry.RemoveBackchannel(id) - backchannelConn.Close() - muxSession.Close() - logger.Close() - return nil + + var firstErr error + for _, closer := range []io.Closer{ + backchannelConn, muxSession, logger, + } { + if err := closer.Close(); err != nil && firstErr == nil { + firstErr = err + } + } + + return firstErr }, }, withSessionInfo(authInfo, id, muxSession), |