@@ -138,40 +138,40 @@ func (ph *PoolHook) OnGet(ctx context.Context, conn *pool.Conn, isNewConn bool)
138138// OnPut is called when a connection is returned to the pool
139139func (ph * PoolHook ) OnPut (ctx context.Context , conn * pool.Conn ) (shouldPool bool , shouldRemove bool , err error ) {
140140 // first check if we should handoff for faster rejection
141- if conn .ShouldHandoff () {
142- // check pending handoff to not queue the same connection twice
143- _ , hasPendingHandoff := ph .pending .Load (conn .GetID ())
144- if ! hasPendingHandoff {
145- // Check for empty endpoint first (synchronous check)
146- if conn .GetHandoffEndpoint () == "" {
147- conn .ClearHandoffState ()
148- } else {
149- if err := ph .queueHandoff (conn ); err != nil {
150- // Failed to queue handoff, remove the connection
151- internal .Logger .Printf (ctx , "Failed to queue handoff: %v" , err )
152- return false , true , nil // Don't pool, remove connection, no error to caller
153- }
141+ if ! conn .ShouldHandoff () {
142+ // Default behavior (no handoff): pool the connection
143+ return true , false , nil
144+ }
154145
155- // Check if handoff was already processed by a worker before we can mark it as queued
156- if ! conn .ShouldHandoff () {
157- // Handoff was already processed - this is normal and the connection should be pooled
158- return true , false , nil
159- }
146+ // check pending handoff to not queue the same connection twice
147+ _ , hasPendingHandoff := ph .pending .Load (conn .GetID ())
148+ if hasPendingHandoff {
149+ // Default behavior (pending handoff): pool the connection
150+ return true , false , nil
151+ }
160152
161- if err := conn .MarkQueuedForHandoff (); err != nil {
162- // If marking fails, check if handoff was processed in the meantime
163- if ! conn .ShouldHandoff () {
164- // Handoff was processed - this is normal, pool the connection
165- return true , false , nil
166- }
167- // Other error - remove the connection
168- return false , true , nil
169- }
170- return true , false , nil
171- }
153+ if err := ph .queueHandoff (conn ); err != nil {
154+ // Failed to queue handoff, remove the connection
155+ internal .Logger .Printf (ctx , "Failed to queue handoff: %v" , err )
156+ // Don't pool, remove connection, no error to caller
157+ return false , true , nil
158+ }
159+
160+ // Check if handoff was already processed by a worker before we can mark it as queued
161+ if ! conn .ShouldHandoff () {
162+ // Handoff was already processed - this is normal and the connection should be pooled
163+ return true , false , nil
164+ }
165+
166+ if err := conn .MarkQueuedForHandoff (); err != nil {
167+ // If marking fails, check if handoff was processed in the meantime
168+ if ! conn .ShouldHandoff () {
169+ // Handoff was processed - this is normal, pool the connection
170+ return true , false , nil
172171 }
172+ // Other error - remove the connection
173+ return false , true , nil
173174 }
174- // Default: pool the connection
175175 return true , false , nil
176176}
177177
0 commit comments