From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id ELt0LnVQpmADiAAAgWs5BA (envelope-from ) for ; Thu, 20 May 2021 14:05:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id OGAkKnVQpmDLawAA1q6Kng (envelope-from ) for ; Thu, 20 May 2021 12:05:09 +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 56932197DA for ; Thu, 20 May 2021 14:05:09 +0200 (CEST) Received: from localhost ([::1]:41194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljhQK-0003Cf-IE for larch@yhetil.org; Thu, 20 May 2021 08:05:08 -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 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=1621512309; 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=16jTgselbCsd1FNYrJgJbY6VoqlzslGKn4GfxtqjsdM=; b=P4l3TatyiqkPt10D0GFD10qkV/+bv05P68itNJHC9yK8ct5afinkz5LIXHEDyTZ9ZF4WMs ol6JRp/gWexcqV7MKhHdHscAdqzEMi8DnzRNGAiG5jU0rbInkoGyyRvzyXlknT9G8rl2FA Yu8Bx20ggX+QkywOBa/JI0fmbzZRLWmBJjMMaK7IpWM4Ky+HJzWhjfxK/+l0G7yeWRhhKC YrSwXJ0kGjhCesQZpyFSPY91g6soKOEZaQ4oh1ASVzTU9yl/FT32z3NuAPmqgrcTN8s+O5 lv3fz20OMtHtTChHiSQqxv2ITw4PJk4Rq3cVxSf5B+Nu9Gs4gbotFHUHfRVRDQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621512309; a=rsa-sha256; cv=none; b=noVZvV+VVpLMR9qWRBHGiAMzV/JLH24+MbYJ+YQkcRwdYKn779j3vBoA+SRUm8bzpYSS63 Ag120O1hBR4N8h2MR9AYffmCGoNA4wfVq8eGVCj3NqHw97SOB1ov2bWVROh7ifIK37nZVc h5p2e++9aq63cAMt/Ig7NsRQXfyVvTU+gWIFGtQeV7nQGzpBrQrSxuvUAoRPQZFxixL9r2 sUnXWnVRe7xSyki6RwDLj+kHy1gsLEo85N4YHzMz5t5Sr1r53xxDelviM5mRK4tMYph/2S xFPzp8430IWayPAf79prvit4uMaM1dqKAfbXEacSWaYXQw2NYrxlfCzhYbdKwA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=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.56 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: 56932197DA X-Spam-Score: 2.56 X-Migadu-Scanner: scn0.migadu.com X-TUID: 3oRLTtaO+GWK 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