From 831a90d3b0f5aa0fda842e79e6f5d213b5a766cc Mon Sep 17 00:00:00 2001 From: Benson Wong Date: Thu, 28 Aug 2025 22:03:14 -0700 Subject: [PATCH] Add different timeout scenarios to Process.checkHealthEndpoint #276 (#278) - add a TCP connection timeout of 500ms - increase HTTP client timeout to 5000ms In this new behaviour the upstream has 500ms to accept a tcp connection and 5000ms to respond to the HTTP request. --- proxy/process.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/proxy/process.go b/proxy/process.go index 9707a07c..d4b1c816 100644 --- a/proxy/process.go +++ b/proxy/process.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "net" "net/http" "net/url" "os/exec" @@ -363,8 +364,18 @@ func (p *Process) stopCommand() { } func (p *Process) checkHealthEndpoint(healthURL string) error { + client := &http.Client{ - Timeout: 500 * time.Millisecond, + // wait a short time for a tcp connection to be established + Transport: &http.Transport{ + DialContext: (&net.Dialer{ + Timeout: 500 * time.Millisecond, + }).DialContext, + }, + + // give a long time to respond to the health check endpoint + // after the connection is established. See issue: 276 + Timeout: 5000 * time.Millisecond, } req, err := http.NewRequest("GET", healthURL, nil)