From debbugs-submit-bounces@debbugs.gnu.org Sat May 29 17:46:35 2021 Received: (at 47174) by debbugs.gnu.org; 29 May 2021 21:46:36 +0000 Received: from localhost ([127.0.0.1]:57860 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ln6mx-0004OE-LF for submit@debbugs.gnu.org; Sat, 29 May 2021 17:46:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40692) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ln6mw-0004O1-1l for 47174@debbugs.gnu.org; Sat, 29 May 2021 17:46:34 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55930) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ln6mq-0002ca-Bi; Sat, 29 May 2021 17:46:28 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=41668 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ln6mq-0003UE-1U; Sat, 29 May 2021 17:46:28 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Christopher Baines Subject: Re: bug#47174: [PATCH 0/2] substitute: Handle closing connections to substitute servers. References: <20210520120413.21644-1-mail@cbaines.net> <20210520120413.21644-2-mail@cbaines.net> Date: Sat, 29 May 2021 23:46:26 +0200 In-Reply-To: <20210520120413.21644-2-mail@cbaines.net> (Christopher Baines's message of "Thu, 20 May 2021 13:04:13 +0100") Message-ID: <87tuml43il.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 47174 Cc: 47174@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Christopher Baines skribis: > When reusing a HTTP connection to fetch multiple nars, and the remote ser= ver > signals that the connection should be closed. Incomplete sentence? > * 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 respon= se)) > + (('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))) >=20=20 > - (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 cas= e. > (fetch uri)) > @@ -565,6 +572,10 @@ PORT." > ;; Wait for the reporter to finish. > (every (compose zero? cdr waitpid) pids) >=20=20 > + ;; Do post-fetch cleanup, maybe closing the HTTP connection if HTT= P is > + ;; being used, and the connection should be closed > + (post-fetch-cleanup) How about returning a Boolean as the third value, =E2=80=98close?=E2=80=99,= indicating whether the port should be closed upon completion? That seems marginally clearer to me that the post-cleanup thunk. Otherwise LGTM, thanks! Ludo=E2=80=99.