fix: check for gateway backend online without http request (#10924)

fixes #10921
This commit is contained in:
Harshavardhana
2020-11-19 10:38:02 -08:00
committed by GitHub
parent d778d9493f
commit 0f9e125cf3
4 changed files with 20 additions and 18 deletions

View File

@@ -18,6 +18,7 @@ package cmd
import (
"context"
"net"
"net/http"
"strings"
"time"
@@ -254,25 +255,18 @@ func ToMinioClientCompleteParts(parts []CompletePart) []minio.CompletePart {
// IsBackendOnline - verifies if the backend is reachable
// by performing a GET request on the URL. returns 'true'
// if backend is reachable.
func IsBackendOnline(ctx context.Context, clnt *http.Client, urlStr string) bool {
func IsBackendOnline(ctx context.Context, host string) bool {
var d net.Dialer
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
defer cancel()
// never follow redirects
clnt.CheckRedirect = func(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, urlStr, nil)
conn, err := d.DialContext(ctx, "tcp", host)
if err != nil {
return false
}
resp, err := clnt.Do(req)
if err != nil {
clnt.CloseIdleConnections()
return !xnet.IsNetworkOrHostDown(err, false)
}
xhttp.DrainBody(resp.Body)
conn.Close()
return true
}