From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id vnQbDb6YoWDXiAAAgWs5BA (envelope-from ) for ; Mon, 17 May 2021 00:12:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 8CcrCL6YoWBSFgAA1q6Kng (envelope-from ) for ; Sun, 16 May 2021 22:12:14 +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 E883918EE0 for ; Mon, 17 May 2021 00:12:13 +0200 (CEST) Received: from localhost ([::1]:59784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1liOzc-0005fh-LM for larch@yhetil.org; Sun, 16 May 2021 18:12:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1liOzS-0005d9-Sa for guix-patches@gnu.org; Sun, 16 May 2021 18:12:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1liOzS-00057O-Lo for guix-patches@gnu.org; Sun, 16 May 2021 18:12:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1liOzS-0002HJ-Hd for guix-patches@gnu.org; Sun, 16 May 2021 18:12:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47174] [PATCH v2 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: Sun, 16 May 2021 22:12: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.16212030848677 (code B ref 47174); Sun, 16 May 2021 22:12:02 +0000 Received: (at 47174) by debbugs.gnu.org; 16 May 2021 22:11:24 +0000 Received: from localhost ([127.0.0.1]:51628 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1liOyq-0002Fs-2w for submit@debbugs.gnu.org; Sun, 16 May 2021 18:11:24 -0400 Received: from mira.cbaines.net ([212.71.252.8]:38896) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1liOyo-0002Fe-Ih for 47174@debbugs.gnu.org; Sun, 16 May 2021 18:11:22 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:8ac0:b4c7:f5c8:7caa]) by mira.cbaines.net (Postfix) with ESMTPSA id C995427BC81 for <47174@debbugs.gnu.org>; Sun, 16 May 2021 23:11:21 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 29660e40 for <47174@debbugs.gnu.org>; Sun, 16 May 2021 22:11:21 +0000 (UTC) From: Christopher Baines Date: Sun, 16 May 2021 23:11:21 +0100 Message-Id: <20210516221121.16705-2-mail@cbaines.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210516221121.16705-1-mail@cbaines.net> References: <20210516221121.16705-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=1621203134; 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=bnm3BKe5FPNU74DZgjqYw3dEElt9En6ZwMGU9Kz1Clk=; b=MgZ9hA+QACw2ogXHxpOXEWLByd+6R9UOb9pMRtYIk9DMuqCJf5Rr3rPppfX3Bsh/O0xxkl hEmNS7VtmeMnuod/63r0I3jeQ5G0OmCwpL5zNpppTpMCLkA+LZkPcBL/sL01WagF2rfs9J Qqp7lF27HTtkyFYCzyW9XBiRMlJyFA7M9wTYWQIdqSz/C06qFVw0n+9WuJmcMr/t14PmTr gtx6j7IrdJ68/V6VX4MNJlbg/5TVKyPqqAWQJeUEioCYdy8++Sxiys00BYk5zoUEO3pvW/ LYYpg+8Ek7w983JNDuVLYoLhq9ash0UXSVQBdIJdpP9jC+yNZJ25HqKBVtfbrA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621203134; a=rsa-sha256; cv=none; b=TPp5X67CHSY5pMkGIgVdtQla3i2wUHCibUUJsvGjCYu/H0S/ATnrayc04FvM1vczz2wZza Cp8+sfR1S4RHosPbAhjowmmoWnfbzR48Ee5j5/hf1Ectsj3HltpnpO0jB1dMZc2bP3xoYy xM7o23EYFAQQkuuQv24Sns17EGrKh7RZoxmprDgtSGCEOOBNFTBLMOV6UaMH3CY5SC1xwI RgZT9LpVN6I3h7yBZ3McW4/l6nRyUU9D33FfWfe/KG98aQYxle8suydJhGcA7Q5J5e0aRl IkRatZQJ4guF2doShkn3vo3hCRwzW7AsZocvEx4pnXfZPxtUrNjF8DrotTcquw== 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: 4.05 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: E883918EE0 X-Spam-Score: 4.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: gVCD+4GbBjAG 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.30.1