diff --git a/canceled/canceled.go b/canceled/canceled.go deleted file mode 100644 index 405cacd3e44..00000000000 --- a/canceled/canceled.go +++ /dev/null @@ -1,16 +0,0 @@ -package canceled - -import ( - "context" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -// Is returns true if err is non-nil and is either context.Canceled, or has a -// grpc code of Canceled. This is useful because cancellations propagate through -// gRPC boundaries, and if we choose to treat in-process cancellations a certain -// way, we usually want to treat cross-process cancellations the same way. -func Is(err error) bool { - return err == context.Canceled || status.Code(err) == codes.Canceled -} diff --git a/canceled/canceled_test.go b/canceled/canceled_test.go deleted file mode 100644 index 251072d8ee8..00000000000 --- a/canceled/canceled_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package canceled - -import ( - "context" - "errors" - "testing" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -func TestCanceled(t *testing.T) { - if !Is(context.Canceled) { - t.Errorf("Expected context.Canceled to be canceled, but wasn't.") - } - if !Is(status.Errorf(codes.Canceled, "hi")) { - t.Errorf("Expected gRPC cancellation to be cancelled, but wasn't.") - } - if Is(errors.New("hi")) { - t.Errorf("Expected random error to not be cancelled, but was.") - } -} diff --git a/core/util.go b/core/util.go index 607b3edbf44..fb514207b3d 100644 --- a/core/util.go +++ b/core/util.go @@ -1,6 +1,7 @@ package core import ( + "context" "crypto" "crypto/ecdsa" "crypto/rand" @@ -27,9 +28,12 @@ import ( "unicode" "github.com/go-jose/go-jose/v4" - "github.com/letsencrypt/boulder/identifier" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" + + "github.com/letsencrypt/boulder/identifier" ) const Unspecified = "Unspecified" @@ -395,6 +399,14 @@ func IsASCII(str string) bool { return true } +// IsCanceled returns true if err is non-nil and is either context.Canceled, or +// has a grpc code of Canceled. This is useful because cancellations propagate +// through gRPC boundaries, and if we choose to treat in-process cancellations a +// certain way, we usually want to treat cross-process cancellations the same way. +func IsCanceled(err error) bool { + return errors.Is(err, context.Canceled) || status.Code(err) == codes.Canceled +} + func Command() string { return path.Base(os.Args[0]) } diff --git a/core/util_test.go b/core/util_test.go index cebbb324557..be43319083b 100644 --- a/core/util_test.go +++ b/core/util_test.go @@ -2,7 +2,9 @@ package core import ( "bytes" + "context" "encoding/json" + "errors" "fmt" "math" "math/big" @@ -13,6 +15,8 @@ import ( "time" "github.com/go-jose/go-jose/v4" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" @@ -362,3 +366,15 @@ func TestHashNames(t *testing.T) { h2 = HashNames([]string{"a"}) test.AssertByteEquals(t, h1, h2) } + +func TestIsCanceled(t *testing.T) { + if !IsCanceled(context.Canceled) { + t.Errorf("Expected context.Canceled to be canceled, but wasn't.") + } + if !IsCanceled(status.Errorf(codes.Canceled, "hi")) { + t.Errorf("Expected gRPC cancellation to be canceled, but wasn't.") + } + if IsCanceled(errors.New("hi")) { + t.Errorf("Expected random error to not be canceled, but was.") + } +} diff --git a/publisher/publisher.go b/publisher/publisher.go index 7e43a56f673..3d377c69891 100644 --- a/publisher/publisher.go +++ b/publisher/publisher.go @@ -25,7 +25,6 @@ import ( cttls "github.com/google/certificate-transparency-go/tls" "github.com/prometheus/client_golang/prometheus" - "github.com/letsencrypt/boulder/canceled" "github.com/letsencrypt/boulder/core" "github.com/letsencrypt/boulder/issuance" blog "github.com/letsencrypt/boulder/log" @@ -261,7 +260,7 @@ func (pub *Impl) SubmitToSingleCTWithResult(ctx context.Context, req *pubpb.Requ sct, err := pub.singleLogSubmit(ctx, chain, req.Kind, ctLog) if err != nil { - if canceled.Is(err) { + if core.IsCanceled(err) { return nil, err } var body string @@ -297,7 +296,7 @@ func (pub *Impl) singleLogSubmit( took := time.Since(start).Seconds() if err != nil { status := "error" - if canceled.Is(err) { + if core.IsCanceled(err) { status = "canceled" } httpStatus := "" diff --git a/va/caa.go b/va/caa.go index 085471623f8..a781fdec420 100644 --- a/va/caa.go +++ b/va/caa.go @@ -13,7 +13,6 @@ import ( "github.com/miekg/dns" "github.com/letsencrypt/boulder/bdns" - "github.com/letsencrypt/boulder/canceled" "github.com/letsencrypt/boulder/core" corepb "github.com/letsencrypt/boulder/core/proto" berrors "github.com/letsencrypt/boulder/errors" @@ -234,7 +233,7 @@ func (va *ValidationAuthorityImpl) processRemoteCAAResults( // the number of remote VAs. The CAA checks will be performed in separate // go-routines. If the result `error` from a remote `isCAAValid` RPC is nil or a // nil `ProblemDetails` instance it is written directly to the `results` chan. -// If the err is a cancelled error it is treated as a nil error. Otherwise the +// If the err is a canceled error it is treated as a nil error. Otherwise the // error/problem is written to the results channel as-is. func (va *ValidationAuthorityImpl) performRemoteCAACheck( ctx context.Context, @@ -248,9 +247,9 @@ func (va *ValidationAuthorityImpl) performRemoteCAACheck( } res, err := rva.IsCAAValid(ctx, req) if err != nil { - if canceled.Is(err) { + if core.IsCanceled(err) { // Handle the cancellation error. - result.Problem = probs.ServerInternal("Remote VA IsCAAValid RPC cancelled") + result.Problem = probs.ServerInternal("Remote VA IsCAAValid RPC canceled") } else { // Handle validation error. va.log.Errf("Remote VA %q.IsCAAValid failed: %s", rva.Address, err) diff --git a/va/va.go b/va/va.go index 34cc3b68b01..4d9a2063583 100644 --- a/va/va.go +++ b/va/va.go @@ -20,7 +20,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/letsencrypt/boulder/bdns" - "github.com/letsencrypt/boulder/canceled" "github.com/letsencrypt/boulder/core" berrors "github.com/letsencrypt/boulder/errors" bgrpc "github.com/letsencrypt/boulder/grpc" @@ -485,7 +484,7 @@ func (va *ValidationAuthorityImpl) performRemoteValidation( // Failed to communicate with the remote VA. failed = append(failed, resp.addr) - if canceled.Is(resp.err) { + if core.IsCanceled(resp.err) { currProb = probs.ServerInternal("Remote PerformValidation RPC canceled") } else { va.log.Errf("Remote VA %q.PerformValidation failed: %s", resp.addr, resp.err)