diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-11 09:49:55 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-09-23 10:02:55 +0300 |
commit | f1a28cb3f75d406ff9380729d2ffa902a5487f8d (patch) | |
tree | 4747dc0e9c23b3558412fcc9bcbf9e5ae1844c70 | |
parent | c4396bffd02b7e4878c18fce31269134ba518bf1 (diff) |
sidechannel: Check error code when closing Unix socket listener
Check the error code when closing the Unix socket listener and drop the
corresponding exclude from our linting rules.
-rw-r--r-- | .golangci.yml | 1 | ||||
-rw-r--r-- | internal/gitaly/hook/sidechannel.go | 15 |
2 files changed, 13 insertions, 3 deletions
diff --git a/.golangci.yml b/.golangci.yml index b86dc3e55..36368721c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -71,7 +71,6 @@ linters-settings: - (*google.golang.org/grpc.ServerConn).Close - (*io.PipeReader).Close - (*io.PipeWriter).Close - - (*net.UnixConn).Close - (*os.File).Close - (io.Closer).Close - (io/fs.File).Close diff --git a/internal/gitaly/hook/sidechannel.go b/internal/gitaly/hook/sidechannel.go index 62c32a059..14fa5304e 100644 --- a/internal/gitaly/hook/sidechannel.go +++ b/internal/gitaly/hook/sidechannel.go @@ -107,7 +107,10 @@ func (wt *SidechannelWaiter) run(callback func(*net.UnixConn) error) { if err != nil { return err } - defer c.Close() + defer func() { + // Error is already checked below. + _ = c.Close() + }() // Eagerly remove the socket directory, in case the process exits before // wt.Close() can run. @@ -115,7 +118,15 @@ func (wt *SidechannelWaiter) run(callback func(*net.UnixConn) error) { return err } - return callback(c) + if err := callback(c); err != nil { + return err + } + + if err := c.Close(); err != nil { + return err + } + + return nil }() } |