Skip to content

Commit 38d2589

Browse files
committed
wrap error instead of adding errorLabels
1 parent 2bf70b3 commit 38d2589

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

x/mongo/driver/topology/pool.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,15 @@ func (pe PoolError) Error() string { return string(pe) }
5050
// poolClearedError is an error returned when the connection pool is cleared or currently paused. It
5151
// is a retryable error.
5252
type poolClearedError struct {
53-
err error
54-
address address.Address
55-
errorLabels []string
53+
err error
54+
address address.Address
5655
}
5756

5857
func (pce poolClearedError) Error() string {
59-
return fmt.Sprintf(
60-
"connection pool for %v was cleared because another operation failed with: %v",
61-
pce.address,
62-
pce.err)
58+
wrappedErr := fmt.Errorf(
59+
"%v: connection pool for %v was cleared because another operation failed with: %v %w",
60+
driver.TransientTransactionError, pce.address, pce.err, pce)
61+
return wrappedErr.Error()
6362
}
6463

6564
// Retryable returns true. All poolClearedErrors are retryable.
@@ -504,7 +503,7 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
504503
}
505504
return nil, ErrPoolClosed
506505
case poolPaused:
507-
err := poolClearedError{err: p.lastClearErr, address: p.address, errorLabels: []string{driver.TransientTransactionError}}
506+
err := poolClearedError{err: p.lastClearErr, address: p.address}
508507
p.stateMu.RUnlock()
509508

510509
duration := time.Since(start)
@@ -1050,7 +1049,7 @@ func (p *pool) clearImpl(err error, serviceID *bson.ObjectID, interruptAllConnec
10501049
}
10511050

10521051
if serviceID == nil {
1053-
pcErr := poolClearedError{err: err, address: p.address, errorLabels: []string{driver.TransientTransactionError}}
1052+
pcErr := poolClearedError{err: err, address: p.address}
10541053

10551054
// Clear the idle connections wait queue.
10561055
p.idleMu.Lock()

x/mongo/driver/topology/pool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ func TestPool_Error(t *testing.T) {
16001600

16011601
var pce poolClearedError
16021602
if errors.As(err, &pce) {
1603-
assert.Contains(t, pce.errorLabels, driver.TransientTransactionError, `expected error to include the "TransientTransactionError" label`)
1603+
assert.Contains(t, pce, driver.TransientTransactionError, `expected error to include the "TransientTransactionError" label`)
16041604
} else {
16051605
t.Errorf("expected poolClearedError, got %v", err)
16061606
}

0 commit comments

Comments
 (0)