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 KHqmFmOIT2DdAwAA0tVLHw (envelope-from ) for ; Mon, 15 Mar 2021 16:16:35 +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 uORVEmOIT2D1IgAAbx9fmQ (envelope-from ) for ; Mon, 15 Mar 2021 16:16:35 +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 D1C4782B1 for ; Mon, 15 Mar 2021 17:16:34 +0100 (CET) Received: from localhost ([::1]:41208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLptR-0005Ns-Li for larch@yhetil.org; Mon, 15 Mar 2021 12:16:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLpsx-0005Gd-RD for guix-patches@gnu.org; Mon, 15 Mar 2021 12:16:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53264) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLpsx-00029z-Ht for guix-patches@gnu.org; Mon, 15 Mar 2021 12:16:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lLpsx-0007qJ-E6 for guix-patches@gnu.org; Mon, 15 Mar 2021 12:16:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47160] [PATCH v2 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: Mon, 15 Mar 2021 16:16:03 +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.161582493630085 (code B ref 47160); Mon, 15 Mar 2021 16:16:03 +0000 Received: (at 47160) by debbugs.gnu.org; 15 Mar 2021 16:15:36 +0000 Received: from localhost ([127.0.0.1]:36575 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLpsV-0007p6-Vf for submit@debbugs.gnu.org; Mon, 15 Mar 2021 12:15:36 -0400 Received: from mira.cbaines.net ([212.71.252.8]:33366) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLpsT-0007op-9r for 47160@debbugs.gnu.org; Mon, 15 Mar 2021 12:15:33 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:8ac0:b4c7:f5c8:7caa]) by mira.cbaines.net (Postfix) with ESMTPSA id E55A827BC54 for <47160@debbugs.gnu.org>; Mon, 15 Mar 2021 16:15:32 +0000 (GMT) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 1b5c9824 for <47160@debbugs.gnu.org>; Mon, 15 Mar 2021 16:15:32 +0000 (UTC) From: Christopher Baines Date: Mon, 15 Mar 2021 16:15:31 +0000 Message-Id: <20210315161532.1716-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=1615824994; 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=JJw7LCvmKC3/t2XxEncJqRcr+36D+nsOIOoRkcmS+Oc=; b=CSknLqQTIyWM+c+Hj40LjPv96zJM+8Ovtj4EylpF3AMh5MfAOwHHBuLwPsRbLuVlYeX534 rEukpOzWn9IkbWEJDScioiaKYvZ8CB9oHHvbSlfiEv3Nrq9d8hotKGAAxW/Wl0i2KcZLHM GvOO4x7L1rqr+YbhPun0ZIr4immqyTOAOKm6YuqY0AU4yMoH5xGuei4E2WUyy5MhIz8u2Q 9lJ5He2K3P31nQDGdA5df3EZeiF5mecH1+2YVejLIaPjcLUCd3KERbcU9IBdSbmCmWb3OI FeRG1KBOkxNC2G42FqreSDzRusZnhACiaxA5beZtYGO4zNV2AQU7regv2M5/2g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615824994; a=rsa-sha256; cv=none; b=GYI9ihhhMol00PYxz0fGsTjAJbI5JRdbQJyHWIyyhkjkzgWthuZf/I7fDUGY1ukYyhToZU yszfvK5E57hdMT2W2XKjo94ZWW/vzMxyOh1A5UqxQnnueeU8FpJbB7GHkEOscyoH2obc2Z oz2stj41lrodzw4eOqDanTGR9/SPDmhDyAc/Ezgx6v/jRu1S2cScPWWJ/r0SjsEbbsaBDF K5uAsTS27FXwgOkVSgtKYQDBWgy4P/uMh6sEdUUZH/qu/l2og2ZuhgIkmRNL3eCWo0ZLlr fQvD1aXWk6hwV573Jn5jMlXVNzm5xR64qjnDjgY86JOmpmgxyxPF6hmxNw/78g== 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: D1C4782B1 X-Spam-Score: 2.60 X-Migadu-Scanner: scn0.migadu.com X-TUID: cLmA8jjUqqC5 In f50f5751fff4cfc6d5abba9681054569694b7a5c, the way fetch was called within process-substitution was changed. As with-cached-connection actually includes important error handling for the opening of a HTTP request (when using a cached connection), this change removed some error handling. This commit adds that error handling back, (call-)with-cached-connection is back, rebranded as call-with-cached-connection-and-error-handling. * guix/scripts/substitute.scm (process-substitution): Retry once for some errors when making HTTP requests to fetch substitutes. --- guix/scripts/substitute.scm | 38 ++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm index 6892aa999b..16ba28455f 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,31 @@ server certificates." (drain-input socket) socket)))))))) +(define (call-with-cached-connection-and-error-handling uri proc) + (define (get-port) + (open-connection-for-uri/cached uri + #:verify-certificate? #f)) + + (let ((port (get-port))) + (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))) + (begin + (close-port port) ; close the port to get a fresh one + (proc (get-port))) + (apply throw key args)))))) + (define* (process-substitution store-item destination #:key cache-urls acl deduplicate? print-build-trace?) @@ -424,11 +450,13 @@ 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)))))) + (call-with-cached-connection-and-error-handling + uri + (lambda (port) + (http-fetch uri #:text? #f + #:port port + #:keep-alive? #t + #:buffered? #f)))))))) (else (leave (G_ "unsupported substitute URI scheme: ~a~%") (uri->string uri))))) -- 2.30.1