Skip to content

Commit bfe0067

Browse files
committed
add TransientTransactionError label to poolClearedError
1 parent fe60b18 commit bfe0067

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

x/mongo/driver/topology/pool.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ 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
53+
err error
54+
address address.Address
55+
errorLabels []string
5556
}
5657

5758
func (pce poolClearedError) Error() string {
@@ -503,7 +504,7 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
503504
}
504505
return nil, ErrPoolClosed
505506
case poolPaused:
506-
err := poolClearedError{err: p.lastClearErr, address: p.address}
507+
err := poolClearedError{err: p.lastClearErr, address: p.address, errorLabels: []string{"TransientTransactionError"}}
507508
p.stateMu.RUnlock()
508509

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

10511052
if serviceID == nil {
1052-
pcErr := poolClearedError{err: err, address: p.address}
1053+
pcErr := poolClearedError{err: err, address: p.address, errorLabels: []string{"TransientTransactionError"}}
10531054

10541055
// Clear the idle connections wait queue.
10551056
p.idleMu.Lock()

x/mongo/driver/topology/pool_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,3 +1584,29 @@ func TestPool_PoolMonitor(t *testing.T) {
15841584
"expected ConnectionCheckOutFailed Duration to be set")
15851585
})
15861586
}
1587+
1588+
func TestPool_Error(t *testing.T) {
1589+
1590+
t.Parallel()
1591+
1592+
t.Run("should have TransientTransactionError", func(t *testing.T) {
1593+
t.Parallel()
1594+
1595+
p := newPool(poolConfig{})
1596+
assert.Equalf(t, poolPaused, p.getState(), "expected new pool to be paused")
1597+
1598+
// Since new pool is paused, checkout should throw poolClearedError.
1599+
_, err := p.checkOut(context.Background())
1600+
1601+
var pce poolClearedError
1602+
if errors.As(err, &pce) {
1603+
expectedLabel := "TransientTransactionError"
1604+
assert.Contains(t, pce.errorLabels, expectedLabel, `expected error to include the "TransientTransactionError" label`)
1605+
} else {
1606+
t.Errorf("expected poolClearedError, got %v", err)
1607+
}
1608+
1609+
p.close(context.Background())
1610+
1611+
})
1612+
}

0 commit comments

Comments
 (0)