@@ -151,8 +151,20 @@ func (ph *PoolHook) OnPut(ctx context.Context, conn *pool.Conn) (shouldPool bool
151151 internal .Logger .Printf (ctx , "Failed to queue handoff: %v" , err )
152152 return false , true , nil // Don't pool, remove connection, no error to caller
153153 }
154+
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+ }
160+
154161 if err := conn .MarkQueuedForHandoff (); err != nil {
155- // If marking fails, remove the connection instead
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
156168 return false , true , nil
157169 }
158170 return true , false , nil
@@ -281,10 +293,12 @@ func (ph *PoolHook) queueHandoff(conn *pool.Conn) error {
281293 return nil
282294 default :
283295 // Queue is full - log and attempt scaling
296+ queueLen := len (ph .handoffQueue )
297+ queueCap := cap (ph .handoffQueue )
284298 if ph .config != nil && ph .config .LogLevel >= 1 { // Warning level
285299 internal .Logger .Printf (context .Background (),
286300 "hitless: handoff queue is full (%d/%d), attempting timeout queuing and scaling workers" ,
287- len ( ph . handoffQueue ), cap ( ph . handoffQueue ) )
301+ queueLen , queueCap )
288302 }
289303 }
290304 }
0 commit comments