Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-08-11 09:58:21 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-09-21 17:27:17 +0300
commitb3d670169895d0f6114214895c57bc5a35e20014 (patch)
treeb1997b2a1efe947160fd98adab24e5bcdcd41c53
parentac89db0f3f90fed73e02f45c18c852ae3660ef99 (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.yml1
-rw-r--r--internal/backchannel/server.go16
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),