Skip to content

Commit bcf62ef

Browse files
committed
GODRIVER-3163: Preserve original cancellation/timeout errors.
1 parent b50f397 commit bcf62ef

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

x/mongo/driver/topology/connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func transformNetworkError(ctx context.Context, originalError error, contextDead
318318

319319
// If there was an error and the context was cancelled, we assume it happened due to the cancellation.
320320
if errors.Is(ctx.Err(), context.Canceled) {
321-
return context.Canceled
321+
return ctx.Err()
322322
}
323323

324324
// If there was a timeout error and the context deadline was used, we convert the error into
@@ -327,7 +327,7 @@ func transformNetworkError(ctx context.Context, originalError error, contextDead
327327
return originalError
328328
}
329329
if netErr, ok := originalError.(net.Error); ok && netErr.Timeout() {
330-
return context.DeadlineExceeded
330+
return fmt.Errorf("%w: %s", context.DeadlineExceeded, originalError.Error())
331331
}
332332

333333
return originalError

0 commit comments

Comments
 (0)