unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Christopher Baines <mail@cbaines.net>
To: 47174@debbugs.gnu.org
Subject: [bug#47174] [PATCH v3 2/2] substitute: Handle closing connections to substitute servers.
Date: Thu, 20 May 2021 13:04:13 +0100	[thread overview]
Message-ID: <20210520120413.21644-2-mail@cbaines.net> (raw)
In-Reply-To: <20210520120413.21644-1-mail@cbaines.net>

When reusing a HTTP connection to fetch multiple nars, and the remote server
signals that the connection should be closed.

* guix/scripts/substitute.scm (process-substitution): Close connections to
substitute servers when a Connection: close header is specified in the
response.
---
 guix/scripts/substitute.scm | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm
index 96f425eaa0..208b8f1273 100755
--- a/guix/scripts/substitute.scm
+++ b/guix/scripts/substitute.scm
@@ -464,7 +464,9 @@ PORT."
     (case (uri-scheme uri)
       ((file)
        (let ((port (open-file (uri-path uri) "r0b")))
-         (values port (stat:size (stat port)))))
+         (values port
+                 (stat:size (stat port))
+                 (const #t))))          ; no cleanup to do
       ((http https)
        (guard (c ((http-get-error? c)
                   (leave (G_ "download from '~a' failed: ~a, ~s~%")
@@ -487,7 +489,12 @@ PORT."
                                        #:keep-alive? #t
                                        #:buffered? #f)))
                (values raw
-                       (response-content-length response)))))))
+                       (response-content-length response)
+                       (match (assq 'connection (response-headers response))
+                         (('connection 'close)
+                          (lambda ()
+                            (close-port port)))
+                         (_ (const #t)))))))))
       (else
        (leave (G_ "unsupported substitute URI scheme: ~a~%")
               (uri->string uri)))))
@@ -504,7 +511,7 @@ PORT."
       (format (current-error-port)
               (G_ "Downloading ~a...~%") (uri->string uri)))
 
-    (let*-values (((raw download-size)
+    (let*-values (((raw download-size post-fetch-cleanup)
                    ;; 'guix publish' without '--cache' doesn't specify a
                    ;; Content-Length, so DOWNLOAD-SIZE is #f in this case.
                    (fetch uri))
@@ -565,6 +572,10 @@ PORT."
       ;; Wait for the reporter to finish.
       (every (compose zero? cdr waitpid) pids)
 
+      ;; Do post-fetch cleanup, maybe closing the HTTP connection if HTTP is
+      ;; being used, and the connection should be closed
+      (post-fetch-cleanup)
+
       ;; Skip a line after what 'progress-reporter/file' printed, and another
       ;; one to visually separate substitutions.  When PRINT-BUILD-TRACE? is
       ;; true, leave it up to (guix status) to prettify things.
-- 
2.31.1





  reply	other threads:[~2021-05-20 12:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 19:21 [bug#47174] [PATCH 0/2] substitute: Handle closing connections to substitute servers Christopher Baines
2021-03-15 19:24 ` [bug#47174] [PATCH 1/2] guix: Alter http-fetch to return the response Christopher Baines
2021-03-15 19:24   ` [bug#47174] [PATCH 2/2] substitute: Handle closing connections to substitute servers Christopher Baines
2021-03-15 20:36     ` [bug#47174] [PATCH 0/2] " Ludovic Courtès
2021-03-15 20:42       ` Christopher Baines
2021-05-16 22:11 ` [bug#47174] [PATCH v2 1/2] guix: Alter http-fetch to return the response Christopher Baines
2021-05-16 22:11   ` [bug#47174] [PATCH v2 2/2] substitute: Handle closing connections to substitute servers Christopher Baines
2021-05-17 14:46     ` Mathieu Othacehe
2021-05-20 10:59       ` Christopher Baines
2021-05-17 14:44   ` [bug#47174] [PATCH v2 1/2] guix: Alter http-fetch to return the response Mathieu Othacehe
2021-05-20 11:12     ` Christopher Baines
2021-05-20 12:04 ` [bug#47174] [PATCH v3 " Christopher Baines
2021-05-20 12:04   ` Christopher Baines [this message]
2021-05-29 21:46     ` [bug#47174] [PATCH 0/2] substitute: Handle closing connections to substitute servers Ludovic Courtès
2021-05-29 21:41   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210520120413.21644-2-mail@cbaines.net \
    --to=mail@cbaines.net \
    --cc=47174@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).