Skip to content

Commit

Permalink
GODRIVER-2952 Update context.Canceled equality comparisons (#1490)
Browse files Browse the repository at this point in the history
Co-authored-by: Ramit Mittal <commitemailoframit@protonmail.com>
  • Loading branch information
prestonvasquez and ramitmittal committed Dec 5, 2023
1 parent c14556a commit bcf3b86
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
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 @@ -625,7 +625,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

0 comments on commit bcf3b86

Please sign in to comment.