From 1c1fa5d4bd6bce4b1326481c00ca9387fd2def33 Mon Sep 17 00:00:00 2001 From: Omar Jarjur Date: Mon, 24 May 2021 14:51:38 -0700 Subject: [PATCH] agent: ignore timeouts in list pending requests When the agent tries to list pending requests and there are no requests to return, there are two possible behaviors: 1. The proxy stops waiting first and returns an empty list of request IDs. 2. The agent stops waiting first and returns a timeout error. For both of these scenarios, the right next steps are the same; the proxy agent should just keep polling for pending requests. However, previously these were handled differently; in the first case the agent would poll again immediately, whereas the second it would log an error message and then use backoff logic to decide how long to wait until polling again. This *could* be handled by simply configuring the agent with a longer timeout than the proxy server, but since the proxy agent and server might not be run by the same administrator, it is better to make the agent handle this scenario gracefully. --- agent/utils/utils.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/agent/utils/utils.go b/agent/utils/utils.go index 2d5c077..005be7c 100644 --- a/agent/utils/utils.go +++ b/agent/utils/utils.go @@ -28,6 +28,7 @@ import ( "math" "math/rand" "net/http" + "net/url" "sync" "time" @@ -225,6 +226,10 @@ func ListPendingRequests(client *http.Client, proxyHost, backendID string, metri proxyReq.Header.Add(HeaderBackendID, backendID) proxyResp, err := client.Do(proxyReq) if err != nil { + if urlErr, ok := err.(*url.Error); ok && urlErr.Timeout() { + // The list pending either timed out or was cancelled; assume this means there are no pending requests. + return nil, nil + } return nil, fmt.Errorf("A proxy request failed: %q", err.Error()) } defer proxyResp.Body.Close()