@@ -3,6 +3,7 @@ package hitless
3
3
import (
4
4
"context"
5
5
"errors"
6
+ "fmt"
6
7
"net"
7
8
"sync"
8
9
"time"
@@ -178,9 +179,16 @@ func (ph *PoolHook) OnPut(ctx context.Context, conn *pool.Conn) (shouldPool bool
178
179
179
180
// startWorkers starts the worker goroutines for processing handoff requests
180
181
func (ph * PoolHook ) startWorkers (count int ) {
181
- for i := 0 ; i < count ; i ++ {
182
- ph .workerWg .Add (1 )
183
- go ph .handoffWorker ()
182
+ select {
183
+ case <- ph .shutdown :
184
+ return
185
+ default :
186
+ hookID := fmt .Sprintf ("%p" , ph )
187
+ internal .Logger .Printf (context .Background (), "hitless: starting %d workers for hook %s" , count , hookID )
188
+ for i := 0 ; i < count ; i ++ {
189
+ ph .workerWg .Add (1 )
190
+ go ph .handoffWorker ()
191
+ }
184
192
}
185
193
}
186
194
@@ -315,14 +323,19 @@ func (ph *PoolHook) shouldScaleDown() bool {
315
323
func (ph * PoolHook ) handoffWorker () {
316
324
defer ph .workerWg .Done ()
317
325
326
+ // Debug: Log worker start with PoolHook pointer for identification
327
+ hookID := fmt .Sprintf ("%p" , ph )
328
+ internal .Logger .Printf (context .Background (), "hitless: worker started for hook %s" , hookID )
329
+
318
330
for {
319
331
select {
320
332
case request := <- ph .handoffQueue :
333
+ internal .Logger .Printf (context .Background (), "hitless: worker %s received request" , hookID )
321
334
// Check if this is a stop worker request
322
335
if request .StopWorkerRequest {
323
336
if ph .config != nil && ph .config .LogLevel >= 2 { // Info level
324
337
internal .Logger .Printf (context .Background (),
325
- "hitless: worker received stop request, exiting" )
338
+ "hitless: worker %s received stop request, exiting" , hookID )
326
339
}
327
340
return // Exit this worker
328
341
}
@@ -332,12 +345,15 @@ func (ph *PoolHook) handoffWorker() {
332
345
case <- ph .shutdown :
333
346
// Clean up the request before exiting
334
347
ph .pending .Delete (request .ConnID )
348
+ internal .Logger .Printf (context .Background (), "hitless: worker %s exiting due to shutdown during request" , hookID )
335
349
return
336
350
default :
337
351
// Continue with processing
352
+ internal .Logger .Printf (context .Background (), "hitless: worker %s processing request" , hookID )
338
353
ph .processHandoffRequest (request )
339
354
}
340
355
case <- ph .shutdown :
356
+ internal .Logger .Printf (context .Background (), "hitless: worker %s exiting due to shutdown" , hookID )
341
357
return
342
358
}
343
359
}
@@ -562,7 +578,10 @@ func (ph *PoolHook) createEndpointDialer(endpoint string) func(context.Context)
562
578
563
579
// Shutdown gracefully shuts down the processor, waiting for workers to complete
564
580
func (ph * PoolHook ) Shutdown (ctx context.Context ) error {
581
+ hookID := fmt .Sprintf ("%p" , ph )
582
+ internal .Logger .Printf (context .Background (), "hitless: Shutdown called for hook %s" , hookID )
565
583
ph .shutdownOnce .Do (func () {
584
+ internal .Logger .Printf (context .Background (), "hitless: closing shutdown channel for hook %s" , hookID )
566
585
close (ph .shutdown )
567
586
568
587
// Clean up scale down timer
0 commit comments