From patchwork Thu May 20 12:04:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 29424 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id A22A427BC81; Thu, 20 May 2021 13:05:17 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 7277827BC78 for ; Thu, 20 May 2021 13:05:17 +0100 (BST) Received: from localhost ([::1]:41194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljhQR-0003Cf-TH for patchwork@mira.cbaines.net; Thu, 20 May 2021 08:05:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljhQE-00038T-JU for guix-patches@gnu.org; Thu, 20 May 2021 08:05:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:49949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ljhQE-0004RJ-Bq for guix-patches@gnu.org; Thu, 20 May 2021 08:05:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ljhQE-0003TB-6F for guix-patches@gnu.org; Thu, 20 May 2021 08:05:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47174] [PATCH v3 2/2] substitute: Handle closing connections to substitute servers. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 20 May 2021 12:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47174 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 47174@debbugs.gnu.org Received: via spool by 47174-submit@debbugs.gnu.org id=B47174.162151225813269 (code B ref 47174); Thu, 20 May 2021 12:05:02 +0000 Received: (at 47174) by debbugs.gnu.org; 20 May 2021 12:04:18 +0000 Received: from localhost ([127.0.0.1]:33261 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ljhPV-0003Rr-V9 for submit@debbugs.gnu.org; Thu, 20 May 2021 08:04:18 -0400 Received: from mira.cbaines.net ([212.71.252.8]:42972) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ljhPT-0003Ra-AJ for 47174@debbugs.gnu.org; Thu, 20 May 2021 08:04:16 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:8ac0:b4c7:f5c8:7caa]) by mira.cbaines.net (Postfix) with ESMTPSA id 50D4F27BC81 for <47174@debbugs.gnu.org>; Thu, 20 May 2021 13:04:14 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id f0eb79bb for <47174@debbugs.gnu.org>; Thu, 20 May 2021 12:04:13 +0000 (UTC) From: Christopher Baines Date: Thu, 20 May 2021 13:04:13 +0100 Message-Id: <20210520120413.21644-2-mail@cbaines.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520120413.21644-1-mail@cbaines.net> References: <20210520120413.21644-1-mail@cbaines.net> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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.