| 67 | } |
| 68 | |
| 69 | type Conn struct { |
| 70 | // Connection identifier for unique tracking |
| 71 | id uint64 |
| 72 | |
| 73 | usedAt atomic.Int64 |
| 74 | lastPutAt atomic.Int64 |
| 75 | dialStartNs atomic.Int64 // Time when dial started (for connection create time metric) |
| 76 | |
| 77 | // Lock-free netConn access using atomic.Value |
| 78 | // Contains *atomicNetConn wrapper, accessed atomically for better performance |
| 79 | netConnAtomic atomic.Value // stores *atomicNetConn |
| 80 | |
| 81 | rd *proto.Reader |
| 82 | bw *bufio.Writer |
| 83 | wr *proto.Writer |
| 84 | |
| 85 | // Lightweight mutex to protect reader operations during handoff and health checks |
| 86 | // Used during: |
| 87 | // - SetNetConn (write lock for resetting reader state) |
| 88 | // - HasBufferedData/PeekReplyTypeSafe (read lock for safe concurrent peek operations) |
| 89 | readerMu sync.RWMutex |
| 90 | |
| 91 | // State machine for connection state management |
| 92 | // Replaces: usable, Inited, used |
| 93 | // Provides thread-safe state transitions with FIFO waiting queue |
| 94 | // States: CREATED → INITIALIZING → IDLE ⇄ IN_USE |
| 95 | // ↓ |
| 96 | // UNUSABLE (handoff/reauth) |
| 97 | // ↓ |
| 98 | // IDLE/CLOSED |
| 99 | stateMachine *ConnStateMachine |
| 100 | |
| 101 | // Handoff metadata - managed separately from state machine |
| 102 | // These are atomic for lock-free access during handoff operations |
| 103 | handoffStateAtomic atomic.Value // stores *HandoffState |
| 104 | handoffRetriesAtomic atomic.Uint32 // retry counter |
| 105 | |
| 106 | pooled bool |
| 107 | pubsub bool |
| 108 | createdAt time.Time |
| 109 | expiresAt time.Time |
| 110 | poolName string // Name of the pool this connection belongs to (for metrics) |
| 111 | |
| 112 | // When a goroutine closes a connection, it usually knows the reason, so closeReason is not needed. |
| 113 | // closeReason is only used when an in-use connection is closed by another goroutine, |
| 114 | // to inform the goroutine using the connection why the connection was closed. |
| 115 | closeReason uberatomic.String |
| 116 | |
| 117 | // closeOnPutReason marks an in-use connection for removal when it is returned |
| 118 | // to the pool. The socket is left open for the in-flight command and closed |
| 119 | // by ConnPool.Put. |
| 120 | closeOnPutReason uberatomic.String |
| 121 | |
| 122 | // maintenanceNotifications upgrade support: relaxed timeouts during migrations/failovers |
| 123 | |
| 124 | // Using atomic operations for lock-free access to avoid mutex contention |
| 125 | relaxedReadTimeoutNs atomic.Int64 // time.Duration as nanoseconds |
| 126 | relaxedWriteTimeoutNs atomic.Int64 // time.Duration as nanoseconds |
nothing calls this directly
no outgoing calls
no test coverage detected