From e001d6791981c5ef3f13f3d9f1cbeff78579ead8 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 22 May 2023 15:27:49 +0100 Subject: 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. --- .../agent-messaging/http/server.scm | 65 ++++++++++++---------- 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'guix-build-coordinator/agent-messaging') 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 -- cgit v1.2.3