From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 1Y2mEum0T2CJWQAA0tVLHw (envelope-from ) for ; Mon, 15 Mar 2021 19:26:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id KP3bDem0T2D4HwAAB5/wlQ (envelope-from ) for ; Mon, 15 Mar 2021 19:26:33 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id BFF0E9EB9 for ; Mon, 15 Mar 2021 20:26:32 +0100 (CET) Received: from localhost ([::1]:58618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLsrH-0004VI-Kd for larch@yhetil.org; Mon, 15 Mar 2021 15:26:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLspq-00036p-OS for guix-patches@gnu.org; Mon, 15 Mar 2021 15:25:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53904) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLspq-0001Bo-Dg for guix-patches@gnu.org; Mon, 15 Mar 2021 15:25:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lLspq-00073o-AW for guix-patches@gnu.org; Mon, 15 Mar 2021 15:25:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47174] [PATCH 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: Mon, 15 Mar 2021 19:25: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.161583629227114 (code B ref 47174); Mon, 15 Mar 2021 19:25:02 +0000 Received: (at 47174) by debbugs.gnu.org; 15 Mar 2021 19:24:52 +0000 Received: from localhost ([127.0.0.1]:37215 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLspg-00073F-Bn for submit@debbugs.gnu.org; Mon, 15 Mar 2021 15:24:52 -0400 Received: from mira.cbaines.net ([212.71.252.8]:35640) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLspe-000731-CP for 47174@debbugs.gnu.org; Mon, 15 Mar 2021 15:24:50 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:8ac0:b4c7:f5c8:7caa]) by mira.cbaines.net (Postfix) with ESMTPSA id 6C29B27BC54 for <47174@debbugs.gnu.org>; Mon, 15 Mar 2021 19:24:49 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 1dfa5663 for <47174@debbugs.gnu.org>; Mon, 15 Mar 2021 19:24:49 +0000 (UTC) From: Christopher Baines Date: Mon, 15 Mar 2021 19:24:49 +0000 Message-Id: <20210315192449.16248-2-mail@cbaines.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210315192449.16248-1-mail@cbaines.net> References: <20210315192449.16248-1-mail@cbaines.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1615836392; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=HTNHN1eT4eUKL4QzYuMkGZtYDI0BgSD2d9KjFCnvWVc=; b=aYC1uVrgTzxMNW9yZUuVYF7P5jT0tJX43UaNYNBeGTS/76yoyGD8axw/gfcZWlyRGp5rwd G1Pl8iOdVwv4DAi0MF24A2nMZ9V1wFiOX8LoPZsmd1E/QmgY3fTGnvphgqPb4ondLPOF2U YZEpT9gB2APWaITPZgSLnz86IUnnnURIO+wOCGg+8rPr7GwIqCLqsnZq/MCGq1ScoqT0EZ GqjxLW3lLwgHYIPY7g1Nd01SGauhMDS/YoUTqCqzerE2lGjDi+btbJKEr9yL/c0q9tcsjz n6DcN/ehE3BOAChHxogRdj9G90IR7nMouleHn8iH98SSePaedbnrNhAEjgMlmg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615836392; a=rsa-sha256; cv=none; b=UpIjb8fRiAwpCFnn6e2oR4/9M9SFyjfH9k+ijQQsHThO9sYbJuOPRAEa/uR5dylt48ujti QgHDDWLbKNOkXPP4Sn1rHiLFdRJ9enqTVnlqLDl7NJMk6xl3bwrvnDQNcfWXWRoQ3aPKL9 GMyYSVPLGWkfe3dBkDcVbikVReww4vaF4j2IL3hjwncKX2G0iMCQ0F6t2fe/nIzOZ7TgEk u33SnNN79lkBzV+J5oIbcsVqfc0TNAFJFgca8nlGKTxJIlvZ7YRTHvBv6taPwY1pWSJpmy c90KQALG8BGAYCAS6i9HiSIj1goBaG50/+nAIBoVMY95t5wR32bxHndsxRNyhQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 2.60 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: BFF0E9EB9 X-Spam-Score: 2.60 X-Migadu-Scanner: scn0.migadu.com X-TUID: mQFeKW2KeUiu 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 cb79ea6927..deb6fbdaa2 100755 --- a/guix/scripts/substitute.scm +++ b/guix/scripts/substitute.scm @@ -406,7 +406,9 @@ the current output 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~%") @@ -434,7 +436,12 @@ the current output port." #:buffered? #f #:verify-certificate? #f))) (values raw - (response-content-length response)))))))) + (response-content-length response) + (match (assq 'connection (response-headers response)) + (('connection 'close) + (lambda () + (close-port (response-port response)))) + (_ (const #t)))))))))) (else (leave (G_ "unsupported substitute URI scheme: ~a~%") (uri->string uri))))) @@ -449,7 +456,7 @@ the current output 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)) @@ -493,6 +500,10 @@ the current output 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. (display "\n\n" (current-error-port)) -- 2.30.1