From bc74793985cee7a8863050882e38fdb04d44acc5 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 15 Nov 2021 00:16:13 +0000 Subject: Handle the case where there are no more bytes to send When submitting an output. This also fixes a regression in not passing report-bytes-sent on to call-with-streaming-http-request. I think this case where the agent is trying to send 0 bytes to the coordinator can happen when the last request to the coordinator times out, probably due to the computing of the hash taking so long. --- guix-build-coordinator/agent-messaging/http.scm | 56 ++++++++++++++----------- 1 file changed, 31 insertions(+), 25 deletions(-) (limited to 'guix-build-coordinator/agent-messaging/http.scm') diff --git a/guix-build-coordinator/agent-messaging/http.scm b/guix-build-coordinator/agent-messaging/http.scm index fc29f1d..e47d660 100644 --- a/guix-build-coordinator/agent-messaging/http.scm +++ b/guix-build-coordinator/agent-messaging/http.scm @@ -300,31 +300,37 @@ (log 'INFO "finished compressing " file ", now sending") (retry-on-error (lambda () - (call-with-input-file template - (lambda (file-port) - (let ((bytes (get-partial-upload-bytes))) - (when bytes - (seek file-port bytes SEEK_SET) - (log 'INFO "resuming upload from byte " bytes)) - - (let-values (((response body) - (call-with-streaming-http-request - (uri #:resume? (integer? bytes)) - (lambda (port) - (with-time-logging - (simple-format #f "sending ~A" file) - (dump-port file-port port - #:buffer-size 65536))) - #:headers `((Authorization . ,auth-value)) - #:method (if bytes 'POST 'PUT)))) - (when (>= (response-code response) 400) - (raise-exception - (make-exception-with-message - (coordinator-handle-failed-request log - 'PUT - (uri-path uri) - response - body))))))))) + (let ((bytes (get-partial-upload-bytes))) + ;; Check if the server has all the bytes + (unless (and bytes + (eq? bytes (stat:size (stat template)))) + + ;; Still more to send + (call-with-input-file template + (lambda (file-port) + (when bytes + (seek file-port bytes SEEK_SET) + (log 'INFO "resuming upload from byte " bytes)) + + (let-values (((response body) + (call-with-streaming-http-request + (uri #:resume? (integer? bytes)) + (lambda (port) + (with-time-logging + (simple-format #f "sending ~A" file) + (dump-port file-port port + #:buffer-size 65536))) + #:headers `((Authorization . ,auth-value)) + #:method (if bytes 'POST 'PUT) + #:report-bytes-sent report-bytes-sent))) + (when (>= (response-code response) 400) + (raise-exception + (make-exception-with-message + (coordinator-handle-failed-request log + 'PUT + (uri-path uri) + response + body)))))))))) #:times 100 #:delay (random 15)) -- cgit v1.2.3