Browse Source

Both io.ReadFull and time.Sleep are now context-aware

pull/7231/head
chrislu 2 months ago
parent
commit
031c67dd5d
  1. 7
      weed/mq/kafka/protocol/fetch.go

7
weed/mq/kafka/protocol/fetch.go

@ -56,16 +56,15 @@ func (h *Handler) handleFetch(ctx context.Context, correlationID uint32, apiVers
start := time.Now() start := time.Now()
deadline := start.Add(time.Duration(maxWaitMs) * time.Millisecond) deadline := start.Add(time.Duration(maxWaitMs) * time.Millisecond)
for time.Now().Before(deadline) { for time.Now().Before(deadline) {
// Check for context cancellation first
// Use context-aware sleep instead of blocking time.Sleep
select { select {
case <-ctx.Done(): case <-ctx.Done():
fmt.Printf("DEBUG: Fetch polling cancelled due to context cancellation\n") fmt.Printf("DEBUG: Fetch polling cancelled due to context cancellation\n")
throttleTimeMs = int32(time.Since(start) / time.Millisecond) throttleTimeMs = int32(time.Since(start) / time.Millisecond)
break break
default:
case <-time.After(10 * time.Millisecond):
// Continue with polling
} }
time.Sleep(10 * time.Millisecond)
if hasDataAvailable() { if hasDataAvailable() {
break break
} }

Loading…
Cancel
Save