MCPcopy
hub / github.com/redis/go-redis / removeConnInternal

Method removeConnInternal

internal/pool/pool.go:1410–1453  ·  view source on GitHub ↗

removeConnInternal is the internal implementation of Remove that optionally frees a turn.

(ctx context.Context, cn *Conn, reason error, freeTurn bool)

Source from the content-addressed store, hash-verified

1408
1409// removeConnInternal is the internal implementation of Remove that optionally frees a turn.
1410func (p *ConnPool) removeConnInternal(ctx context.Context, cn *Conn, reason error, freeTurn bool) {
1411 // Lock-free atomic read - no mutex overhead!
1412 hookManager := p.hookManager.Load()
1413
1414 if hookManager != nil {
1415 hookManager.ProcessOnRemove(ctx, cn, reason)
1416 }
1417
1418 removed := p.removeConnWithLock(cn)
1419
1420 if freeTurn {
1421 p.freeTurn()
1422 }
1423
1424 // Only emit metric decrements if we actually removed the connection from the map.
1425 // If removed is false, Close() already removed it and emitted the -1 delta.
1426 if removed {
1427 // Notify metrics: connection removed (assume from used state)
1428 if cb := getMetricConnectionStateChangeCallback(); cb != nil {
1429 cb(ctx, cn, MetricStateUsed, "")
1430 }
1431 // Record connection count decrement (connection removed, assume from used state)
1432 if cb := getMetricConnectionCountCallback(); cb != nil {
1433 cb(ctx, -1, cn, "used", false)
1434 }
1435 }
1436
1437 // Only emit connection closed if we actually owned the removal.
1438 // If removed is false, Close() already emitted connectionClosed for this conn.
1439 if removed {
1440 if cb := getMetricConnectionClosedCallback(); cb != nil {
1441 reasonStr := "unknown"
1442 if reason != nil {
1443 reasonStr = reason.Error()
1444 }
1445 cb(ctx, cn, reasonStr, reason)
1446 }
1447 }
1448
1449 _ = p.closeConn(cn)
1450
1451 // Check if we need to create new idle connections to maintain MinIdleConns
1452 p.checkMinIdleConns()
1453}
1454
1455// CloseConn closes a connection and records metrics.
1456// Parameters:

Callers 3

putConnMethod · 0.95
RemoveMethod · 0.95
RemoveWithoutTurnMethod · 0.95

Calls 10

removeConnWithLockMethod · 0.95
freeTurnMethod · 0.95
closeConnMethod · 0.95
checkMinIdleConnsMethod · 0.95
ProcessOnRemoveMethod · 0.80
LoadMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected