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 ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
@ -13,6 +14,8 @@ import (
"github.com/zeebo/errs" "github.com/zeebo/errs"
"go.uber.org/zap" "go.uber.org/zap"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"storj.io/common/errs2"
) )
// ErrEndpoint is the default error class for the authorization endpoint. // 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 { group.Go(func() error {
defer cancel() 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() return group.Wait()

View File

@ -7,6 +7,7 @@ package admin
import ( import (
"context" "context"
"crypto/subtle" "crypto/subtle"
"errors"
"net" "net"
"net/http" "net/http"
@ -14,6 +15,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"storj.io/common/errs2"
"storj.io/storj/satellite/accounting" "storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/console" "storj.io/storj/satellite/console"
) )
@ -105,7 +107,11 @@ func (server *Server) Run(ctx context.Context) error {
}) })
group.Go(func() error { group.Go(func() error {
defer cancel() 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() return group.Wait()
} }

View File

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

View File

@ -5,6 +5,7 @@ package marketingweb
import ( import (
"context" "context"
"errors"
"html/template" "html/template"
"net" "net"
"net/http" "net/http"
@ -16,6 +17,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"storj.io/common/errs2"
"storj.io/storj/satellite/rewards" "storj.io/storj/satellite/rewards"
) )
@ -270,7 +272,11 @@ func (s *Server) Run(ctx context.Context) error {
}) })
group.Go(func() error { group.Go(func() error {
defer cancel() 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() return group.Wait()

View File

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

View File

@ -7,6 +7,7 @@ import (
"context" "context"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors"
"net" "net"
"net/http" "net/http"
"reflect" "reflect"
@ -215,7 +216,11 @@ func (peer *Peer) Run(ctx context.Context) (err error) {
group.Go(func() error { group.Go(func() error {
defer cancel() defer cancel()
peer.Log.Info("Versioning server started.", zap.String("Address", peer.Addr())) 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() return group.Wait()
} }