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

Method CloseConn

internal/pool/pool.go:1461–1477  ·  view source on GitHub ↗

CloseConn closes a connection and records metrics. Parameters: - ctx: context for metric callbacks (enables trace-to-metric correlation) - cn: the connection to close - reason: why the connection is being closed (use CloseReason* constants) - fromState: the metric state the connection was in (use Me

(ctx context.Context, cn *Conn, reason string, fromState string)

Source from the content-addressed store, hash-verified

1459// - reason: why the connection is being closed (use CloseReason* constants)
1460// - fromState: the metric state the connection was in (use MetricState* constants)
1461func (p *ConnPool) CloseConn(ctx context.Context, cn *Conn, reason string, fromState string) error {
1462 if hookManager := p.hookManager.Load(); hookManager != nil {
1463 hookManager.ProcessOnRemove(ctx, cn, errors.New(reason))
1464 }
1465
1466 removed := p.removeConnWithLock(cn)
1467
1468 // Only emit UpDownCounter decrements if we actually removed the connection.
1469 // If removed is false, Close() already removed it and emitted the -1 delta.
1470 // Only emit connection closed if we actually owned the removal.
1471 // If removed is false, Close() already emitted connectionClosed for this conn.
1472 if removed {
1473 p.recordConnectionMetrics(ctx, cn, reason, fromState)
1474 }
1475
1476 return p.closeConn(cn)
1477}
1478
1479func (p *ConnPool) recordConnectionMetrics(ctx context.Context, cn *Conn, reason string, fromState string) {
1480 // Record connection state change: connection is being removed from the specified state

Callers 2

getConnMethod · 0.95

Calls 5

removeConnWithLockMethod · 0.95
closeConnMethod · 0.95
ProcessOnRemoveMethod · 0.80
LoadMethod · 0.45

Tested by 1