diff options
author | Christopher Baines <mail@cbaines.net> | 2023-05-23 09:37:11 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-05-23 10:17:05 +0100 |
commit | 29858eb553137172176cd00ea3d8c007590c7594 (patch) | |
tree | da42ad5630417ab35390f20d3e05ed862de11fa5 | |
parent | af550daaabeab4da5e980b647860c6f1df1b2033 (diff) | |
download | build-coordinator-29858eb553137172176cd00ea3d8c007590c7594.tar build-coordinator-29858eb553137172176cd00ea3d8c007590c7594.tar.gz |
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.
-rw-r--r-- | guix-build-coordinator/agent-messaging/http/server.scm | 124 |
1 files 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)))) |