From 112f64eb98299242b9acadd0463d33c1123f5b9d Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Wed, 1 May 2024 19:08:38 -0400 Subject: [PATCH] GODRIVER-3163 Preserve original cancellation/timeout errors. (#1625) (cherry picked from commit 091ec6c1c671947ce64accefcb5a2de48813f743) --- x/mongo/driver/topology/connection.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/mongo/driver/topology/connection.go b/x/mongo/driver/topology/connection.go index 00f44bee6b..37e0027bff 100644 --- a/x/mongo/driver/topology/connection.go +++ b/x/mongo/driver/topology/connection.go @@ -318,7 +318,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 errors.Is(ctx.Err(), context.Canceled) { - return context.Canceled + return ctx.Err() } // 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 return originalError } if netErr, ok := originalError.(net.Error); ok && netErr.Timeout() { - return context.DeadlineExceeded + return fmt.Errorf("%w: %s", context.DeadlineExceeded, originalError.Error()) } return originalError