OnGet is called when a connection is retrieved from the pool
(_ context.Context, conn *pool.Conn, _ bool)
| 121 | |
| 122 | // OnGet is called when a connection is retrieved from the pool |
| 123 | func (ph *PoolHook) OnGet(_ context.Context, conn *pool.Conn, _ bool) (accept bool, err error) { |
| 124 | // Check if connection is marked for handoff |
| 125 | // This prevents using connections that have received MOVING notifications |
| 126 | if conn.ShouldHandoff() { |
| 127 | return false, ErrConnectionMarkedForHandoffWithState |
| 128 | } |
| 129 | |
| 130 | // Check if connection is usable (not in UNUSABLE or CLOSED state) |
| 131 | // This ensures we don't return connections that are currently being handed off or re-authenticated. |
| 132 | if !conn.IsUsable() { |
| 133 | return false, ErrConnectionMarkedForHandoff |
| 134 | } |
| 135 | |
| 136 | return true, nil |
| 137 | } |
| 138 | |
| 139 | // OnPut is called when a connection is returned to the pool |
| 140 | func (ph *PoolHook) OnPut(ctx context.Context, conn *pool.Conn) (shouldPool bool, shouldRemove bool, err error) { |