Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lightning: fix context.Cancelled nested in aws err #49764

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion br/pkg/lightning/log/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_library(
deps = [
"//pkg/util/logutil",
"@com_github_aws_aws_sdk_go//aws/awserr",
"@com_github_aws_aws_sdk_go//aws/request",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_log//:log",
"@org_golang_google_grpc//codes",
Expand Down
12 changes: 9 additions & 3 deletions br/pkg/lightning/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/pingcap/errors"
pclog "github.com/pingcap/log"
"github.com/pingcap/tidb/pkg/util/logutil"
Expand Down Expand Up @@ -188,8 +187,15 @@ func IsContextCanceledError(err error) bool {
}

// see https://github.com/aws/aws-sdk-go/blob/9d1f49ba/aws/credentials/credentials.go#L246-L249
if v, ok := err.(awserr.Error); ok {
return v.Code() == request.CanceledErrorCode
// 2 cases that have meet:
// awserr.New("RequestCanceled", "request context canceled", err) and the nested err is context.Canceled
// awserr.New( "MultipartUpload", "upload multipart failed", err) and the nested err is the upper one
if v, ok := err.(awserr.BatchedErrors); ok {
for _, origErr := range v.OrigErrs() {
if IsContextCanceledError(origErr) {
return true
}
}
}
return false
}
Expand Down
7 changes: 5 additions & 2 deletions br/pkg/lightning/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ func TestIsContextCanceledError(t *testing.T) {
require.True(t, log.IsContextCanceledError(context.Canceled))
require.True(t, log.IsContextCanceledError(status.Error(codes.Canceled, "")))
require.True(t, log.IsContextCanceledError(errors.Annotate(context.Canceled, "foo")))
require.True(t, log.IsContextCanceledError(awserr.New(request.CanceledErrorCode, "", nil)))
require.True(t, log.IsContextCanceledError(awserr.New(request.CanceledErrorCode, "", context.Canceled)))
require.True(t, log.IsContextCanceledError(awserr.New(
"MultipartUpload", "upload multipart failed",
awserr.New(request.CanceledErrorCode, "", context.Canceled))))
require.True(t, log.IsContextCanceledError(awserr.New(request.ErrCodeRequestError, "", context.Canceled)))

require.False(t, log.IsContextCanceledError(awserr.New(request.ErrCodeRequestError, "", nil)))
require.False(t, log.IsContextCanceledError(nil))
}
Loading