Skip to content

Commit

Permalink
fix early timeout bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlygeek committed Nov 10, 2024
1 parent 63d4a7d commit 5944a86
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions proxy/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -203,7 +204,7 @@ func (pm *ProxyManager) checkHealthEndpoint(cmdCtx context.Context) error {
return err
}

ctx, cancel := context.WithTimeout(cmdCtx, 250*time.Millisecond)
ctx, cancel := context.WithTimeout(cmdCtx, time.Second)
defer cancel()
req = req.WithContext(ctx)
resp, err := client.Do(req)
Expand All @@ -214,7 +215,10 @@ func (pm *ProxyManager) checkHealthEndpoint(cmdCtx context.Context) error {
// check if the context was cancelled
select {
case <-ctx.Done():
return context.Cause(ctx)
err := context.Cause(ctx)
if !errors.Is(err, context.DeadlineExceeded) {
return err
}
default:
}

Expand Down Expand Up @@ -307,7 +311,6 @@ func (pm *ProxyManager) proxyRequest(w http.ResponseWriter, r *http.Request) {
n, err := resp.Body.Read(buf)
if n > 0 {
if _, writeErr := w.Write(buf[:n]); writeErr != nil {
http.Error(w, writeErr.Error(), http.StatusInternalServerError)
return
}
if flusher, ok := w.(http.Flusher); ok {
Expand Down

0 comments on commit 5944a86

Please sign in to comment.