aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/agent-messaging
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2021-11-15 00:16:13 +0000
committerChristopher Baines <mail@cbaines.net>2021-11-15 00:16:13 +0000
commitbc74793985cee7a8863050882e38fdb04d44acc5 (patch)
treefcf27c6878e9a9591009f93cef0560f210d6a418 /guix-build-coordinator/agent-messaging
parent87508af9566d9f7dbacfd8478a353d612a811e38 (diff)
downloadbuild-coordinator-bc74793985cee7a8863050882e38fdb04d44acc5.tar
build-coordinator-bc74793985cee7a8863050882e38fdb04d44acc5.tar.gz
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.
Diffstat (limited to 'guix-build-coordinator/agent-messaging')
-rw-r--r--guix-build-coordinator/agent-messaging/http.scm56
1 files changed, 31 insertions, 25 deletions
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))