From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id uF3fHoFDUWDOawAA0tVLHw (envelope-from ) for ; Tue, 16 Mar 2021 23:47:13 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id cOuOGoFDUWBbIwAAbx9fmQ (envelope-from ) for ; Tue, 16 Mar 2021 23:47:13 +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 3692B16B48 for ; Wed, 17 Mar 2021 00:47:13 +0100 (CET) Received: from localhost ([::1]:54934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMJP6-0000mK-2w for larch@yhetil.org; Tue, 16 Mar 2021 19:47:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMJOw-0000kM-Qa for guix-patches@gnu.org; Tue, 16 Mar 2021 19:47:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58154) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lMJOw-000605-JC for guix-patches@gnu.org; Tue, 16 Mar 2021 19:47:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lMJOw-0007YA-Gu for guix-patches@gnu.org; Tue, 16 Mar 2021 19:47:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47160] [PATCH 1/2] scripts: substitute: Add back some error handling. References: <20210315151133.16282-1-mail@cbaines.net> In-Reply-To: <20210315151133.16282-1-mail@cbaines.net> Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 16 Mar 2021 23:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47160 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 47160@debbugs.gnu.org Received: via spool by 47160-submit@debbugs.gnu.org id=B47160.161593839128973 (code B ref 47160); Tue, 16 Mar 2021 23:47:02 +0000 Received: (at 47160) by debbugs.gnu.org; 16 Mar 2021 23:46:31 +0000 Received: from localhost ([127.0.0.1]:41465 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lMJOR-0007XA-EM for submit@debbugs.gnu.org; Tue, 16 Mar 2021 19:46:31 -0400 Received: from mira.cbaines.net ([212.71.252.8]:33878) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lMJOP-0007Ww-7H for 47160@debbugs.gnu.org; Tue, 16 Mar 2021 19:46:29 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:8ac0:b4c7:f5c8:7caa]) by mira.cbaines.net (Postfix) with ESMTPSA id BD80A27BC54 for <47160@debbugs.gnu.org>; Tue, 16 Mar 2021 23:46:28 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 6117e4c4 for <47160@debbugs.gnu.org>; Tue, 16 Mar 2021 23:46:28 +0000 (UTC) From: Christopher Baines Date: Tue, 16 Mar 2021 23:46:27 +0000 Message-Id: <20210316234628.24479-1-mail@cbaines.net> X-Mailer: git-send-email 2.30.1 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=1615938433; 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=1M7YBSFW5ggiBPyTof8SVjVgve5YtfowUCCE9wg9QyA=; b=GH8LLv8F9XglIEvoB4hG+rnatdgwS1hf2oar2/fDlYAd+yHzT1xata4prRfnHhHCsDB3rb uitNczKiLb9gDPZQVueZlJNjDseiLxdRRhpqcsv/5EehgJynLOyTZ85kgt4oiSYNbNuIYy Yu5gKsFg4Ca/CIuuPbaoP9NgXOTmt5BtulPHMsQ0Wkin2lyGvTo6CNN0u7WvnVboaBsR9T xHdZClyAezycOsHZC9yTchiSlOzlsjrZhCRKiqlZJswjgT/6F1tu5/cFgFHhqV4/noTPBH YKz526lyhWXLNX27k/SeWrqo7vvHpAwi4v4lT+DHHvMEYiHkE8PdO3Q2JDY23g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615938433; a=rsa-sha256; cv=none; b=ruVCs2fRMV0PZ/b92OIHY9F7tsj5yopJgOLXb0EyYC0FqhObKr897gtGzF69mluEkhi1T6 ra87gzkFue/Zx19DZJREPZwPhotzFo6O8SDwsTp1W4be3Rm3PhCTe7wKjYWyXS4Prqz8fl WUjbgkS6lAJotlee//uDaK4rnICr9Ao+YqLlU5WA9m5fRyEz1X1Lmrfniu/XgdV4Xw8d6O TOrcQDw7qKTAGQfb/GWsQvAOD4bzjuFSavLnESQOwSWYnIpmTXUlbyTEF7zk987/Z0hNY2 dYi6PKA5xIfVArET9DyuuyrQjmpsLeuJkH18844ChW3JPlXZn9A6E0e+ukqUfw== 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: 3692B16B48 X-Spam-Score: 2.60 X-Migadu-Scanner: scn0.migadu.com X-TUID: FGtN4910Ldff In f50f5751fff4cfc6d5abba9681054569694b7a5c, the way fetch was called within process-substitution was changed. As call-with-cached-connection actually includes important error handling for the opening of a HTTP request, this change removed some error handling. This commit adds that back. Fixes . * guix/scripts/substitute.scm (call-with-cached-connection): New procedure. (with-cached-connection): New syntax rule. (process-substitution): Retry once for some errors when making HTTP requests to fetch substitutes. --- guix/scripts/substitute.scm | 39 ++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm index 6892aa999b..812f2999ab 100755 --- a/guix/scripts/substitute.scm +++ b/guix/scripts/substitute.scm @@ -45,6 +45,7 @@ #:select (uri-abbreviation nar-uri-abbreviation (open-connection-for-uri . guix:open-connection-for-uri))) + #:autoload (gnutls) (error/invalid-session) #:use-module (guix progress) #:use-module ((guix build syscalls) #:select (set-thread-name)) @@ -377,6 +378,32 @@ server certificates." (drain-input socket) socket)))))))) +(define (call-with-cached-connection uri proc) + (let ((port (open-connection-for-uri/cached uri + #:verify-certificate? #f))) + (catch #t + (lambda () + (proc port)) + (lambda (key . args) + ;; If PORT was cached and the server closed the connection in the + ;; meantime, we get EPIPE. In that case, open a fresh connection + ;; and retry. We might also get 'bad-response or a similar + ;; exception from (web response) later on, once we've sent the + ;; request, or a ERROR/INVALID-SESSION from GnuTLS. + (if (or (and (eq? key 'system-error) + (= EPIPE (system-error-errno `(,key ,@args)))) + (and (eq? key 'gnutls-error) + (eq? (first args) error/invalid-session)) + (memq key '(bad-response bad-header bad-header-component))) + (proc (open-connection-for-uri/cached uri + #:verify-certificate? #f + #:fresh? #t)) + (apply throw key args)))))) + +(define-syntax-rule (with-cached-connection uri port exp ...) + "Bind PORT with EXP... to a socket connected to URI." + (call-with-cached-connection uri (lambda (port) exp ...))) + (define* (process-substitution store-item destination #:key cache-urls acl deduplicate? print-build-trace?) @@ -424,11 +451,11 @@ the current output port." (call-with-connection-error-handling uri (lambda () - (http-fetch uri #:text? #f - #:open-connection open-connection-for-uri/cached - #:keep-alive? #t - #:buffered? #f - #:verify-certificate? #f)))))) + (with-cached-connection uri port + (http-fetch uri #:text? #f + #:port port + #:keep-alive? #t + #:buffered? #f))))))) (else (leave (G_ "unsupported substitute URI scheme: ~a~%") (uri->string uri))))) @@ -715,6 +742,8 @@ if needed, as expected by the daemon's agent." ;;; Local Variables: ;;; eval: (put 'with-timeout 'scheme-indent-function 1) ;;; eval: (put 'with-redirected-error-port 'scheme-indent-function 0) +;;; eval: (put 'with-cached-connection 'scheme-indent-function 2) +;;; eval: (put 'call-with-cached-connection 'scheme-indent-function 1) ;;; End: ;;; substitute.scm ends here -- 2.30.1