all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#47160] [PATCH] scripts: substitute: Add back some error handling.
@ 2021-03-15 15:11 Christopher Baines
  2021-03-15 15:20 ` Ludovic Courtès
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Christopher Baines @ 2021-03-15 15:11 UTC (permalink / raw)
  To: 47160

In f50f5751fff4cfc6d5abba9681054569694b7a5c, the way fetch was called within
process-substitution was changed.  As with-cached-connection actually includes
important error handling for the opening of a HTTP request (when using a
cached connection), this change removed some error handling.

This commit adds that error handling back,
with-cached-connection/call-with-cached-connection is back, rebranded as
call-with-fresh-connection-retry.

* guix/scripts/substitute.scm (process-substitution): Retry once for some
errors when making HTTP requests to fetch substitutes.
---
 guix/scripts/substitute.scm | 38 ++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm
index 6892aa999b..2c9b45023f 100755
--- a/guix/scripts/substitute.scm
+++ b/guix/scripts/substitute.scm
@@ -45,6 +45,7 @@
                 #:select (uri-abbreviation nar-uri-abbreviation
                           (open-connection-for-uri
                            . guix:open-connection-for-uri)))
+  #:autoload   (gnutls) (error/invalid-session)
   #:use-module (guix progress)
   #:use-module ((guix build syscalls)
                 #:select (set-thread-name))
@@ -401,6 +402,31 @@ the current output port."
     (apply dump-file/deduplicate
            (append args (list #:store (%store-prefix)))))
 
+  (define (call-with-fresh-connection-retry uri proc)
+    (define (get-port)
+      (open-connection-for-uri/cached uri
+                                      #:verify-certificate? #f))
+
+    (let ((port (get-port)))
+      (catch #t
+        (lambda ()
+          (proc port))
+        (lambda (key . args)
+          ;; If PORT was cached and the server closed the connection in the
+          ;; meantime, we get EPIPE.  In that case, open a fresh connection
+          ;; and retry.  We might also get 'bad-response or a similar
+          ;; exception from (web response) later on, once we've sent the
+          ;; request, or a ERROR/INVALID-SESSION from GnuTLS.
+          (if (or (and (eq? key 'system-error)
+                       (= EPIPE (system-error-errno `(,key ,@args))))
+                  (and (eq? key 'gnutls-error)
+                       (eq? (first args) error/invalid-session))
+                  (memq key '(bad-response bad-header bad-header-component)))
+              (begin
+                (close-port port)       ; close the port to get a fresh one
+                (proc (get-port)))
+              (apply throw key args))))))
+
   (define (fetch uri)
     (case (uri-scheme uri)
       ((file)
@@ -424,11 +450,13 @@ the current output port."
            (call-with-connection-error-handling
             uri
             (lambda ()
-              (http-fetch uri #:text? #f
-                          #:open-connection open-connection-for-uri/cached
-                          #:keep-alive? #t
-                          #:buffered? #f
-                          #:verify-certificate? #f))))))
+              (call-with-fresh-connection-retry
+               uri
+               (lambda (port)
+                 (http-fetch uri #:text? #f
+                             #:port port
+                             #:keep-alive? #t
+                             #:buffered? #f))))))))
       (else
        (leave (G_ "unsupported substitute URI scheme: ~a~%")
               (uri->string uri)))))
-- 
2.30.1





^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-03-17 20:47 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15 15:11 [bug#47160] [PATCH] scripts: substitute: Add back some error handling Christopher Baines
2021-03-15 15:20 ` Ludovic Courtès
2021-03-15 16:15   ` Christopher Baines
2021-03-15 20:51     ` Ludovic Courtès
2021-03-15 21:33       ` Christopher Baines
2021-03-16 20:34         ` Ludovic Courtès
2021-03-15 16:15 ` [bug#47160] [PATCH v2 1/2] " Christopher Baines
2021-03-15 16:15   ` [bug#47160] [PATCH v2 2/2] scripts: substitute: Tweak error reporting in process-substitution Christopher Baines
2021-03-16 21:30   ` [bug#47160] [PATCH] scripts: substitute: Add back some error handling Ludovic Courtès
2021-03-16 23:11     ` Christopher Baines
2021-03-16 23:46 ` [bug#47160] [PATCH 1/2] " Christopher Baines
2021-03-16 23:46   ` [bug#47160] [PATCH 2/2] scripts: substitute: Tweak error reporting in process-substitution Christopher Baines
2021-03-17 20:18   ` [bug#47160] [PATCH] scripts: substitute: Add back some error handling Ludovic Courtès
2021-03-17 20:46     ` bug#47160: " Christopher Baines

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.