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

GODRIVER-2952 Update context.Canceled equality comparisons #1490

Merged
merged 1 commit into from
Dec 5, 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
6 changes: 3 additions & 3 deletions x/mongo/driver/topology/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func transformNetworkError(ctx context.Context, originalError error, contextDead
}

// If there was an error and the context was cancelled, we assume it happened due to the cancellation.
if ctx.Err() == context.Canceled {
if errors.Is(ctx.Err(), context.Canceled) {
return context.Canceled
}

Expand Down Expand Up @@ -858,15 +858,15 @@ func newCancellListener() *cancellListener {

// Listen blocks until the provided context is cancelled or listening is aborted
// via the StopListening function. If this detects that the context has been
// cancelled (i.e. ctx.Err() == context.Canceled), the provided callback is
// cancelled (i.e. errors.Is(ctx.Err(), context.Canceled), the provided callback is
// called to abort in-progress work. Even if the context expires, this function
// will block until StopListening is called.
func (c *cancellListener) Listen(ctx context.Context, abortFn func()) {
c.aborted = false

select {
case <-ctx.Done():
if ctx.Err() == context.Canceled {
if errors.Is(ctx.Err(), context.Canceled) {
c.aborted = true
abortFn()
}
Expand Down
2 changes: 1 addition & 1 deletion x/mongo/driver/topology/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func TestConnection(t *testing.T) {
assert.True(t, ok, "expected error %v to be of type %T", connectErr, ConnectionError{})

isTimeout := func(err error) bool {
if err == context.DeadlineExceeded {
if errors.Is(err, context.DeadlineExceeded) {
return true
}
if ne, ok := err.(net.Error); ok {
Expand Down
4 changes: 2 additions & 2 deletions x/mongo/driver/topology/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func (s *Server) ProcessError(err error, conn driver.Connection) driver.ProcessE
if netErr, ok := wrappedConnErr.(net.Error); ok && netErr.Timeout() {
return driver.NoChange
}
if wrappedConnErr == context.Canceled || wrappedConnErr == context.DeadlineExceeded {
if errors.Is(wrappedConnErr, context.Canceled) || errors.Is(wrappedConnErr, context.DeadlineExceeded) {
return driver.NoChange
}

Expand Down Expand Up @@ -623,7 +623,7 @@ func (s *Server) update() {
// Retry after the first timeout before clearing the pool in case of a FAAS pause as
// described in GODRIVER-2577.
if err := unwrapConnectionError(desc.LastError); err != nil && timeoutCnt < 1 {
if err == context.Canceled || err == context.DeadlineExceeded {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
timeoutCnt++
// We want to immediately retry on timeout error. Continue to next loop.
return true
Expand Down
Loading