Skip to content

Commit a4758c2

Browse files
committed
add debug and make sure workers are not started after shutdown
1 parent 34edec2 commit a4758c2

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

hitless/pool_hook.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package hitless
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"net"
78
"sync"
89
"time"
@@ -178,9 +179,16 @@ func (ph *PoolHook) OnPut(ctx context.Context, conn *pool.Conn) (shouldPool bool
178179

179180
// startWorkers starts the worker goroutines for processing handoff requests
180181
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+
}
184192
}
185193
}
186194

@@ -315,14 +323,19 @@ func (ph *PoolHook) shouldScaleDown() bool {
315323
func (ph *PoolHook) handoffWorker() {
316324
defer ph.workerWg.Done()
317325

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+
318330
for {
319331
select {
320332
case request := <-ph.handoffQueue:
333+
internal.Logger.Printf(context.Background(), "hitless: worker %s received request", hookID)
321334
// Check if this is a stop worker request
322335
if request.StopWorkerRequest {
323336
if ph.config != nil && ph.config.LogLevel >= 2 { // Info level
324337
internal.Logger.Printf(context.Background(),
325-
"hitless: worker received stop request, exiting")
338+
"hitless: worker %s received stop request, exiting", hookID)
326339
}
327340
return // Exit this worker
328341
}
@@ -332,12 +345,15 @@ func (ph *PoolHook) handoffWorker() {
332345
case <-ph.shutdown:
333346
// Clean up the request before exiting
334347
ph.pending.Delete(request.ConnID)
348+
internal.Logger.Printf(context.Background(), "hitless: worker %s exiting due to shutdown during request", hookID)
335349
return
336350
default:
337351
// Continue with processing
352+
internal.Logger.Printf(context.Background(), "hitless: worker %s processing request", hookID)
338353
ph.processHandoffRequest(request)
339354
}
340355
case <-ph.shutdown:
356+
internal.Logger.Printf(context.Background(), "hitless: worker %s exiting due to shutdown", hookID)
341357
return
342358
}
343359
}
@@ -562,7 +578,10 @@ func (ph *PoolHook) createEndpointDialer(endpoint string) func(context.Context)
562578

563579
// Shutdown gracefully shuts down the processor, waiting for workers to complete
564580
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)
565583
ph.shutdownOnce.Do(func() {
584+
internal.Logger.Printf(context.Background(), "hitless: closing shutdown channel for hook %s", hookID)
566585
close(ph.shutdown)
567586

568587
// Clean up scale down timer

0 commit comments

Comments
 (0)