Created
November 9, 2019 08:31
-
-
Save kasvith/75e1b1c71e766dbcb44f987d72dd4f01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proxy.ErrorHandler = func(writer http.ResponseWriter, request *http.Request, e error) { | |
log.Printf("[%s] %s\n", serverUrl.Host, e.Error()) | |
retries := GetRetryFromContext(request) | |
if retries < 3 { | |
select { | |
case <-time.After(10 * time.Millisecond): | |
ctx := context.WithValue(request.Context(), Retry, retries+1) | |
proxy.ServeHTTP(writer, request.WithContext(ctx)) | |
} | |
return | |
} | |
// after 3 retries, mark this backend as down | |
serverPool.MarkBackendStatus(serverUrl, false) | |
// if the same request routing for few attempts with different backends, increase the count | |
attempts := GetAttemptsFromContext(request) | |
log.Printf("%s(%s) Attempting retry %d\n", request.RemoteAddr, request.URL.Path, attempts) | |
ctx := context.WithValue(request.Context(), Attempts, attempts+1) | |
lb(writer, request.WithContext(ctx)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment