Skip to content

Commit 3efd5e2

Browse files
FGaspermatthewdale
authored andcommitted
GODRIVER-3163 Preserve original cancellation/timeout errors. (#1625)
1 parent 09fda3b commit 3efd5e2

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
@@ -320,7 +320,7 @@ func transformNetworkError(ctx context.Context, originalError error, contextDead
320320

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

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

335335
return originalError

0 commit comments

Comments
 (0)