From 5944a86e8656334611c7e75fd428004c10f3a1d7 Mon Sep 17 00:00:00 2001 From: Benson Wong Date: Sat, 9 Nov 2024 20:08:40 -0800 Subject: [PATCH] fix early timeout bug --- proxy/manager.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/proxy/manager.go b/proxy/manager.go index db5d0e8..5330b14 100644 --- a/proxy/manager.go +++ b/proxy/manager.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -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) @@ -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: } @@ -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 {