From 29858eb553137172176cd00ea3d8c007590c7594 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 23 May 2023 09:37:11 +0100 Subject: Better handle the output hashing being completed for upload requests This currently causes an error on the server side and a timeout on the client side. --- .../agent-messaging/http/server.scm | 124 ++++++++++++--------- 1 file changed, 70 insertions(+), 54 deletions(-) diff --git a/guix-build-coordinator/agent-messaging/http/server.scm b/guix-build-coordinator/agent-messaging/http/server.scm index b8c9e2a..c001546 100644 --- a/guix-build-coordinator/agent-messaging/http/server.scm +++ b/guix-build-coordinator/agent-messaging/http/server.scm @@ -861,31 +861,39 @@ port. Also, the port used can be changed by passing the --port option.\n" content-length tmp-output-file-name)))) - (let ((channel - (start-computing-output-hash-via-channel - output-hash-channel - request - response-port - uuid - tmp-output-file-name - output-file-name))) - - (log-msg logger - 'DEBUG - "PUT /build/" uuid "/output/" output-name ": " - "finished receiving " tmp-output-file-name) - - (list - (build-response - #:code 200 - #:headers '((content-type . (text/plain)))) - (lambda (response-port) - ;; Make sure NGinx gets the response headers - (force-output (request-port request)) - - (report-progress-computing-hash channel - request - response-port))))) + (if (file-exists? output-file-name) + (render-json + '(("success" . "upload already finished")) + #:code 200) + (if (file-exists? tmp-output-file-name) + (let ((channel + (start-computing-output-hash-via-channel + output-hash-channel + request + response-port + uuid + tmp-output-file-name + output-file-name))) + + (log-msg logger + 'DEBUG + "PUT /build/" uuid "/output/" output-name ": " + "finished receiving " tmp-output-file-name) + + (list + (build-response + #:code 200 + #:headers '((content-type . (text/plain)))) + (lambda (response-port) + ;; Make sure NGinx gets the response headers + (force-output (request-port request)) + + (report-progress-computing-hash channel + request + response-port)))) + (render-json + '(("error" . "tmp file missing")) + #:code 400)))) (render-json '(("error" . "access denied")) #:code 403)))) @@ -945,35 +953,43 @@ port. Also, the port used can be changed by passing the --port option.\n" tmp-output-file-name #:append? #t))) - (let ((channel - (start-computing-output-hash-via-channel - output-hash-channel - request - response-port - uuid - tmp-output-file-name - 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 - #:code 200 - #:headers '((content-type . (text/plain)))) - (lambda (response-port) - ;; Make sure NGinx gets the response headers - (force-output (request-port request)) - - (report-progress-computing-hash channel - request - response-port))))) + (if (file-exists? output-file-name) + (render-json + '(("success" . "upload already finished")) + #:code 200) + (if (file-exists? tmp-output-file-name) + (let ((channel + (start-computing-output-hash-via-channel + output-hash-channel + request + response-port + uuid + tmp-output-file-name + 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 + #:code 200 + #:headers '((content-type . (text/plain)))) + (lambda (response-port) + ;; Make sure NGinx gets the response headers + (force-output (request-port request)) + + (report-progress-computing-hash channel + request + response-port)))) + (render-json + '(("error" . "tmp file missing")) + #:code 400)))) (render-json '(("error" . "access denied")) #:code 403)))) -- cgit v1.2.3