[ARVADOS] created: 8af4c5ffe2d0bf7f009f8821945aa100ddf02279
git at public.curoverse.com
git at public.curoverse.com
Wed Apr 29 15:09:44 EDT 2015
at 8af4c5ffe2d0bf7f009f8821945aa100ddf02279 (commit)
commit 8af4c5ffe2d0bf7f009f8821945aa100ddf02279
Author: Tom Clegg <tom at curoverse.com>
Date: Wed Apr 29 14:56:22 2015 -0400
3145: Respond to PUT without reading request body if no volumes are writable.
diff --git a/services/keepstore/handlers.go b/services/keepstore/handlers.go
index 9e178fb..f462b0a 100644
--- a/services/keepstore/handlers.go
+++ b/services/keepstore/handlers.go
@@ -156,37 +156,46 @@ func PutBlockHandler(resp http.ResponseWriter, req *http.Request) {
hash := mux.Vars(req)["hash"]
- // Read the block data to be stored.
- // If the request exceeds BLOCKSIZE bytes, issue a HTTP 500 error.
- //
+ // Detect as many error conditions as possible before reading
+ // the body: avoid transmitting data that will not end up
+ // being written anyway.
+
if req.ContentLength > BLOCKSIZE {
http.Error(resp, TooLongError.Error(), TooLongError.HTTPCode)
return
}
+ if len(KeepVM.AllWritable()) == 0 {
+ http.Error(resp, FullError.Error(), FullError.HTTPCode)
+ return
+ }
+
buf := make([]byte, req.ContentLength)
nread, err := io.ReadFull(req.Body, buf)
if err != nil {
http.Error(resp, err.Error(), 500)
+ return
} else if int64(nread) < req.ContentLength {
http.Error(resp, "request truncated", 500)
- } else {
- if err := PutBlock(buf, hash); err == nil {
- // Success; add a size hint, sign the locator if
- // possible, and return it to the client.
- return_hash := fmt.Sprintf("%s+%d", hash, len(buf))
- api_token := GetApiToken(req)
- if PermissionSecret != nil && api_token != "" {
- expiry := time.Now().Add(permission_ttl)
- return_hash = SignLocator(return_hash, api_token, expiry)
- }
- resp.Write([]byte(return_hash + "\n"))
- } else {
- ke := err.(*KeepError)
- http.Error(resp, ke.Error(), ke.HTTPCode)
- }
+ return
}
- return
+
+ err = PutBlock(buf, hash)
+ if err != nil {
+ ke := err.(*KeepError)
+ http.Error(resp, ke.Error(), ke.HTTPCode)
+ return
+ }
+
+ // Success; add a size hint, sign the locator if possible, and
+ // return it to the client.
+ return_hash := fmt.Sprintf("%s+%d", hash, len(buf))
+ api_token := GetApiToken(req)
+ if PermissionSecret != nil && api_token != "" {
+ expiry := time.Now().Add(permission_ttl)
+ return_hash = SignLocator(return_hash, api_token, expiry)
+ }
+ resp.Write([]byte(return_hash + "\n"))
}
// IndexHandler
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list