all: separate err check for http

We want to avoid net/http dependency in errs2 package, hence we removed
http.ErrServerClosed from IgnoreCanceled and IsCanceled check. Now we
need to add that check explicitly to every http endpoint.

Change-Id: I62b1cc0a0a2d3b43301d713a7951e5022145f88f
This commit is contained in:
Egon Elbre 2020-04-16 18:50:22 +03:00
parent 2dce4c232c
commit a129a8bd35
6 changed files with 42 additions and 6 deletions

View File

@ -5,6 +5,7 @@ package authorization
import (
"context"
"errors"
"fmt"
"net"
"net/http"
@ -13,6 +14,8 @@ import (
"github.com/zeebo/errs"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"storj.io/common/errs2"
)
// ErrEndpoint is the default error class for the authorization endpoint.
@ -57,7 +60,11 @@ func (endpoint *Endpoint) Run(ctx context.Context) (err error) {
})
group.Go(func() error {
defer cancel()
return endpoint.server.Serve(endpoint.listener)
err := endpoint.server.Serve(endpoint.listener)
if errs2.IsCanceled(err) || errors.Is(err, http.ErrServerClosed) {
err = nil
}
return err
})
return group.Wait()

View File

@ -7,6 +7,7 @@ package admin
import (
"context"
"crypto/subtle"
"errors"
"net"
"net/http"
@ -14,6 +15,7 @@ import (
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"storj.io/common/errs2"
"storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/console"
)
@ -105,7 +107,11 @@ func (server *Server) Run(ctx context.Context) error {
})
group.Go(func() error {
defer cancel()
return Error.Wrap(server.server.Serve(server.listener))
err := server.server.Serve(server.listener)
if errs2.IsCanceled(err) || errors.Is(err, http.ErrServerClosed) {
err = nil
}
return Error.Wrap(err)
})
return group.Wait()
}

View File

@ -7,6 +7,7 @@ import (
"context"
"crypto/subtle"
"encoding/json"
"errors"
"fmt"
"html/template"
"mime"
@ -28,6 +29,7 @@ import (
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"storj.io/common/errs2"
"storj.io/common/uuid"
"storj.io/storj/pkg/auth"
"storj.io/storj/satellite/console"
@ -220,7 +222,11 @@ func (server *Server) Run(ctx context.Context) (err error) {
})
group.Go(func() error {
defer cancel()
return server.server.Serve(server.listener)
err := server.server.Serve(server.listener)
if errs2.IsCanceled(err) || errors.Is(err, http.ErrServerClosed) {
err = nil
}
return err
})
return group.Wait()

View File

@ -5,6 +5,7 @@ package marketingweb
import (
"context"
"errors"
"html/template"
"net"
"net/http"
@ -16,6 +17,7 @@ import (
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"storj.io/common/errs2"
"storj.io/storj/satellite/rewards"
)
@ -270,7 +272,11 @@ func (s *Server) Run(ctx context.Context) error {
})
group.Go(func() error {
defer cancel()
return Error.Wrap(s.server.Serve(s.listener))
err := s.server.Serve(s.listener)
if errs2.IsCanceled(err) || errors.Is(err, http.ErrServerClosed) {
err = nil
}
return Error.Wrap(err)
})
return group.Wait()

View File

@ -5,6 +5,7 @@ package consoleserver
import (
"context"
"errors"
"net"
"net/http"
"path/filepath"
@ -15,6 +16,7 @@ import (
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"storj.io/common/errs2"
"storj.io/storj/storagenode/console"
"storj.io/storj/storagenode/console/consoleapi"
"storj.io/storj/storagenode/heldamount"
@ -118,7 +120,11 @@ func (server *Server) Run(ctx context.Context) (err error) {
})
group.Go(func() error {
defer cancel()
return server.server.Serve(server.listener)
err := server.server.Serve(server.listener)
if errs2.IsCanceled(err) || errors.Is(err, http.ErrServerClosed) {
err = nil
}
return err
})
return group.Wait()

View File

@ -7,6 +7,7 @@ import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"net"
"net/http"
"reflect"
@ -215,7 +216,11 @@ func (peer *Peer) Run(ctx context.Context) (err error) {
group.Go(func() error {
defer cancel()
peer.Log.Info("Versioning server started.", zap.String("Address", peer.Addr()))
return errs2.IgnoreCanceled(peer.Server.Endpoint.Serve(peer.Server.Listener))
err := peer.Server.Endpoint.Serve(peer.Server.Listener)
if errs2.IsCanceled(err) || errors.Is(err, http.ErrServerClosed) {
err = nil
}
return err
})
return group.Wait()
}