|
|
@ -251,10 +251,17 @@ func (h *Handler) HandleConn(ctx context.Context, conn net.Conn) error { |
|
|
select { |
|
|
select { |
|
|
case <-ctx.Done(): |
|
|
case <-ctx.Done(): |
|
|
fmt.Printf("DEBUG: [%s] Context cancelled before reading message header\n", connectionID) |
|
|
fmt.Printf("DEBUG: [%s] Context cancelled before reading message header\n", connectionID) |
|
|
|
|
|
// Give a small delay to ensure proper cleanup
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond) |
|
|
return ctx.Err() |
|
|
return ctx.Err() |
|
|
default: |
|
|
default: |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Set a much shorter read deadline to prevent hanging in CI
|
|
|
|
|
|
if err := conn.SetReadDeadline(time.Now().Add(2 * time.Second)); err != nil { |
|
|
|
|
|
fmt.Printf("DEBUG: [%s] Failed to set short read deadline: %v\n", connectionID, err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Read message size (4 bytes)
|
|
|
// Read message size (4 bytes)
|
|
|
fmt.Printf("DEBUG: [%s] About to read message size header\n", connectionID) |
|
|
fmt.Printf("DEBUG: [%s] About to read message size header\n", connectionID) |
|
|
var sizeBytes [4]byte |
|
|
var sizeBytes [4]byte |
|
|
@ -266,8 +273,16 @@ func (h *Handler) HandleConn(ctx context.Context, conn net.Conn) error { |
|
|
|
|
|
|
|
|
// Check if it's a timeout error
|
|
|
// Check if it's a timeout error
|
|
|
if netErr, ok := err.(net.Error); ok && netErr.Timeout() { |
|
|
if netErr, ok := err.(net.Error); ok && netErr.Timeout() { |
|
|
fmt.Printf("DEBUG: [%s] Read timeout due to context cancellation\n", connectionID) |
|
|
|
|
|
return ctx.Err() |
|
|
|
|
|
|
|
|
fmt.Printf("DEBUG: [%s] Read timeout (likely due to context cancellation or client disconnect)\n", connectionID) |
|
|
|
|
|
// Check if context was cancelled
|
|
|
|
|
|
select { |
|
|
|
|
|
case <-ctx.Done(): |
|
|
|
|
|
fmt.Printf("DEBUG: [%s] Context was cancelled, returning context error\n", connectionID) |
|
|
|
|
|
return ctx.Err() |
|
|
|
|
|
default: |
|
|
|
|
|
fmt.Printf("DEBUG: [%s] Timeout without context cancellation, treating as client disconnect\n", connectionID) |
|
|
|
|
|
return nil // treat as clean disconnect
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Use centralized error classification
|
|
|
// Use centralized error classification
|
|
|
|