aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2023-05-22 15:27:49 +0100
committerChristopher Baines <mail@cbaines.net>2023-05-22 15:27:49 +0100
commite001d6791981c5ef3f13f3d9f1cbeff78579ead8 (patch)
tree32d615262d36dcd012397302993640c28c405efe
parent61f0b5de0ad06d393576540dfb77460616aaed40 (diff)
downloadbuild-coordinator-e001d6791981c5ef3f13f3d9f1cbeff78579ead8.tar
build-coordinator-e001d6791981c5ef3f13f3d9f1cbeff78579ead8.tar.gz
Better handle upload requests with no content
The idea with these is to allow the agent to resume waiting for the coordinator to finish computing the output hash.
-rw-r--r--guix-build-coordinator/agent-messaging/http/server.scm65
1 files changed, 37 insertions, 28 deletions
diff --git a/guix-build-coordinator/agent-messaging/http/server.scm b/guix-build-coordinator/agent-messaging/http/server.scm
index 806c201..b8c9e2a 100644
--- a/guix-build-coordinator/agent-messaging/http/server.scm
+++ b/guix-build-coordinator/agent-messaging/http/server.scm
@@ -915,30 +915,35 @@ port. Also, the port used can be changed by passing the --port option.\n"
(let* ((output-file-name
(build-output-file-location datastore uuid output-name))
(tmp-output-file-name
- (string-append output-file-name ".tmp")))
-
- ;; If the output file exists, delete it, as it's being uploaded
- ;; again
- (when (file-exists? output-file-name)
- (log-msg logger
- 'WARN
- "POST /build/" uuid "/output/" output-name "/partial: "
- "deleting " output-file-name)
- (delete-file output-file-name))
-
- (if (member '(chunked) (request-transfer-encoding request))
- ;; Older agents may use chunked encoding for this request
- (call-with-worker-thread
- chunked-request-channel
- (lambda ()
- (receive-file body
- #f
- tmp-output-file-name
- #:append? #t)))
- (receive-file body
- (request-content-length request)
- tmp-output-file-name
- #:append? #t))
+ (string-append output-file-name ".tmp"))
+ (content-length
+ (request-content-length request)))
+
+ ;; An agent may make this request with a content length of 0 to
+ ;; resume waiting for the hash to be computed
+ (unless (= content-length 0)
+ ;; If the output file exists, delete it, as it's being uploaded
+ ;; again
+ (when (file-exists? output-file-name)
+ (log-msg logger
+ 'WARN
+ "POST /build/" uuid "/output/" output-name "/partial: "
+ "deleting " output-file-name)
+ (delete-file output-file-name))
+
+ (if (member '(chunked) (request-transfer-encoding request))
+ ;; Older agents may use chunked encoding for this request
+ (call-with-worker-thread
+ chunked-request-channel
+ (lambda ()
+ (receive-file body
+ #f
+ tmp-output-file-name
+ #:append? #t)))
+ (receive-file body
+ (request-content-length request)
+ tmp-output-file-name
+ #:append? #t)))
(let ((channel
(start-computing-output-hash-via-channel
@@ -949,10 +954,14 @@ port. Also, the port used can be changed by passing the --port option.\n"
tmp-output-file-name
output-file-name)))
- (log-msg logger
- 'DEBUG
- "POST /build/" uuid "/output/" output-name "/partial: "
- "finished receiving " tmp-output-file-name)
+ (apply log-msg
+ logger
+ 'DEBUG
+ "POST /build/" uuid "/output/" output-name "/partial: "
+ (if (= content-length 0)
+ `("sending response for " ,tmp-output-file-name
+ " upload")
+ `("finished receiving " ,tmp-output-file-name)))
(list
(build-response