X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/eee13aa7003afff6ccf390ac92fe2b4a525d16f9..f32690a4a18f85909c0a04de83ecf7819f127df8:/services/keepproxy/keepproxy.go diff --git a/services/keepproxy/keepproxy.go b/services/keepproxy/keepproxy.go index a6019387ef..ea14c6ca48 100644 --- a/services/keepproxy/keepproxy.go +++ b/services/keepproxy/keepproxy.go @@ -1,10 +1,10 @@ package main import ( - "git.curoverse.com/arvados.git/sdk/go/keepclient" - "git.curoverse.com/arvados.git/sdk/go/arvadosclient" "flag" "fmt" + "git.curoverse.com/arvados.git/sdk/go/arvadosclient" + "git.curoverse.com/arvados.git/sdk/go/keepclient" "github.com/gorilla/mux" "io" "io/ioutil" @@ -30,6 +30,7 @@ func main() { no_get bool no_put bool default_replicas int + timeout int64 pidfile string ) @@ -61,6 +62,12 @@ func main() { 2, "Default number of replicas to write if not specified by the client.") + flagset.Int64Var( + &timeout, + "timeout", + 15, + "Timeout on requests to internal Keep services (default 15 seconds)") + flagset.StringVar( &pidfile, "pid", @@ -91,6 +98,8 @@ func main() { kc.Want_replicas = default_replicas + kc.Client.Timeout = time.Duration(timeout) * time.Second + listener, err = net.Listen("tcp", listen) if err != nil { log.Fatalf("Could not listen on %v", listen) @@ -105,7 +114,6 @@ func main() { s := <-sig log.Println("caught signal:", s) listener.Close() - listener = nil }(term) signal.Notify(term, syscall.SIGTERM) signal.Notify(term, syscall.SIGINT) @@ -284,7 +292,7 @@ func (this GetBlockHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reques locator := keepclient.MakeLocator2(hash, hints) - log.Printf("%s: %s %s", GetRemoteAddress(req), req.Method, hash) + log.Printf("%s: %s %s begin", GetRemoteAddress(req), req.Method, hash) var pass bool var tok string @@ -309,32 +317,43 @@ func (this GetBlockHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reques blocklen, _, err = kc.AuthorizedAsk(hash, locator.Signature, locator.Timestamp) } - if blocklen > 0 { + if blocklen > -1 { resp.Header().Set("Content-Length", fmt.Sprint(blocklen)) + } else { + log.Printf("%s: %s %s Keep server did not return Content-Length", + GetRemoteAddress(req), req.Method, hash) } + var status = 0 switch err { case nil: + status = http.StatusOK if reader != nil { n, err2 := io.Copy(resp, reader) - if n != blocklen { - log.Printf("%s: %s %s mismatched return %v with Content-Length %v error %v", GetRemoteAddress(req), req.Method, hash, n, blocklen, err2) + if blocklen > -1 && n != blocklen { + log.Printf("%s: %s %s %v %v mismatched copy size expected Content-Length: %v", + GetRemoteAddress(req), req.Method, hash, status, n, blocklen) } else if err2 == nil { - log.Printf("%s: %s %s success returned %v bytes", GetRemoteAddress(req), req.Method, hash, n) + log.Printf("%s: %s %s %v %v", + GetRemoteAddress(req), req.Method, hash, status, n) } else { - log.Printf("%s: %s %s returned %v bytes error %v", GetRemoteAddress(req), req.Method, hash, n, err.Error()) + log.Printf("%s: %s %s %v %v copy error: %v", + GetRemoteAddress(req), req.Method, hash, status, n, err2.Error()) } } else { - log.Printf("%s: %s %s success", GetRemoteAddress(req), req.Method, hash) + log.Printf("%s: %s %s %v 0", GetRemoteAddress(req), req.Method, hash, status) } case keepclient.BlockNotFound: + status = http.StatusNotFound http.Error(resp, "Not found", http.StatusNotFound) default: + status = http.StatusBadGateway http.Error(resp, err.Error(), http.StatusBadGateway) } if err != nil { - log.Printf("%s: %s %s error %s", GetRemoteAddress(req), req.Method, hash, err.Error()) + log.Printf("%s: %s %s %v error: %v", + GetRemoteAddress(req), req.Method, hash, status, err.Error()) } } @@ -359,7 +378,7 @@ func (this PutBlockHandler) ServeHTTP(resp http.ResponseWriter, req *http.Reques log.Printf("%s: %s %s Content-Length %v", GetRemoteAddress(req), req.Method, hash, contentLength) - if contentLength < 1 { + if contentLength < 0 { http.Error(resp, "Must include Content-Length header", http.StatusLengthRequired) return }