From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id mGs2B1eIT2BJbgAA0tVLHw (envelope-from ) for ; Mon, 15 Mar 2021 16:16:23 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id mBHgAleIT2DqIAAAbx9fmQ (envelope-from ) for ; Mon, 15 Mar 2021 16:16:23 +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 901E917EF0 for ; Mon, 15 Mar 2021 17:16:22 +0100 (CET) Received: from localhost ([::1]:40980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLptF-0005HF-K4 for larch@yhetil.org; Mon, 15 Mar 2021 12:16:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLpsw-0005F2-Ue for guix-patches@gnu.org; Mon, 15 Mar 2021 12:16:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53262) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLpsw-00029G-MT for guix-patches@gnu.org; Mon, 15 Mar 2021 12:16:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lLpsw-0007pv-Hv for guix-patches@gnu.org; Mon, 15 Mar 2021 12:16:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47160] [PATCH] scripts: substitute: Add back some error handling. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 15 Mar 2021 16:16: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: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 47160@debbugs.gnu.org Received: via spool by 47160-submit@debbugs.gnu.org id=B47160.161582490630016 (code B ref 47160); Mon, 15 Mar 2021 16:16:02 +0000 Received: (at 47160) by debbugs.gnu.org; 15 Mar 2021 16:15:06 +0000 Received: from localhost ([127.0.0.1]:36569 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLps2-0007o4-47 for submit@debbugs.gnu.org; Mon, 15 Mar 2021 12:15:06 -0400 Received: from mira.cbaines.net ([212.71.252.8]:33360) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lLpry-0007nc-IF for 47160@debbugs.gnu.org; Mon, 15 Mar 2021 12:15:05 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:8ac0:b4c7:f5c8:7caa]) by mira.cbaines.net (Postfix) with ESMTPSA id B5CDF27BC52; Mon, 15 Mar 2021 16:15:01 +0000 (GMT) Received: from capella (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id 92234124; Mon, 15 Mar 2021 16:15:00 +0000 (UTC) References: <20210315151133.16282-1-mail@cbaines.net> <8735wwh29g.fsf@gnu.org> User-agent: mu4e 1.4.15; emacs 27.1 From: Christopher Baines In-reply-to: <8735wwh29g.fsf@gnu.org> Date: Mon, 15 Mar 2021 16:15:00 +0000 Message-ID: <874khcfl6j.fsf@cbaines.net> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" 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=1615824982; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: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=pZx6c3r8aACCqn17cIceojlm6xZbthogHrfe/XE4hHQ=; b=GkFRyOaz1fGQ36WPKj8RQ5qak2ZNIxy5K0Iy1g3/eznh+j2C1Dc3CagEmBg2dMCrgxr/hy mLAS5u4YrE2a+3HxHcU1CNe75zIpvd5KiienF+gcqe954PknlP39kYs23CUoulbbqMFGHo tEY4poY77r2q/CQDiIcgBjtFY+DndFMMYNxEfEXLVEh7ww6lhre/ZOZRwQoz+O75H/mD8b eVJLGRAxDT5duk7cR7n1OZjMCEch4cTgUVBTBctp5KeVqCaMnu9nzzXrANOXRcFyeRclF8 bGJO9SEHbSrLyfoGztHSa6QmQsNeryvehm0HfWO+Rt3dUAde8czzDAmQROKZqQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615824982; a=rsa-sha256; cv=none; b=G3itubLGtkaIQNv8u0oQAFAKN/vOA2GUUYh+IZ4l+xajW6rCk5rSLVme3xLgWEW1Y6B9dU v45IBiInGQNT1kH3Ti3u9n6eptPWZXNKkGzFII2HcDMo+u+OBqPdaig8oAyuusMRGgBjQ9 ivozTP9UTMt1utUhayplkLd3MkTQ6OAyLclTAIY9qv632DRRqVeJQlA6O0EJsPGzuBKBZY eEwxyo4d8i7sUJ7DGm+xkmS8ndGmzHFuT1VbMmLOwBgNOTn4SeHFWoPvxqklgRolVy4iOH tLutfmSEhVngld4g1+XXZsdCeGJSu9EJS3btBc3DzBQe2puJ+/W0Lq2P/tComg== 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: -4.50 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: 901E917EF0 X-Spam-Score: -4.50 X-Migadu-Scanner: scn0.migadu.com X-TUID: 7QoxJuHofyqt --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s writes: > Hi, > > Christopher Baines skribis: > >> In f50f5751fff4cfc6d5abba9681054569694b7a5c, the way fetch was called wi= thin >> process-substitution was changed. As with-cached-connection actually in= cludes >> 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, >> with-cached-connection/call-with-cached-connection is back, rebranded as >> call-with-fresh-connection-retry. >> >> * guix/scripts/substitute.scm (process-substitution): Retry once for some >> errors when making HTTP requests to fetch substitutes. > > [...] > >> + (define (call-with-fresh-connection-retry 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 connec= tion >> + ;; 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) >> + (=3D 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-compon= ent))) >> + (begin >> + (close-port port) ; close the port to get a fresh= one >> + (proc (get-port))) >> + (apply throw key args)))))) > > I think this should be at the top level for clarity. It used to have > =E2=80=98cached=E2=80=99 in its name because catching all these exception= s is something > you wouldn=E2=80=99t normally do; it only makes sense in the context of c= ached > connections. I initially tried to just put the error handling in just where it's needed, but that was difficult since the http-fetch bit needs to happen again when there's a relevant error. The two things: getting a port which maybe is a cached connection and handling some errors plus potentially re-running proc is difficult to capture in a name, but "call-with-cached-connection-and-error-handling" is an improvement over "with-cached-connection" I think. >> (define (fetch uri) >> (case (uri-scheme uri) >> ((file) >> @@ -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/cac= hed >> - #:keep-alive? #t >> - #:buffered? #f >> - #:verify-certificate? #f)))))) >> + (call-with-fresh-connection-retry >> + uri >> + (lambda (port) >> + (http-fetch uri #:text? #f >> + #:port port >> + #:keep-alive? #t >> + #:buffered? #f)))))))) > > Does =E2=80=98call-with-connection-error-handling=E2=80=99 still make sen= se here? > There=E2=80=99s already =E2=80=98with-networking=E2=80=99 at the top leve= l to do proper > networking error reporting. So, looking back, the call-with-connection-error-handling error handling was related to (call-)with-cached-connection, but it was only relevant inside of fetch-narinfos, as that's when open-connection-for-uri/maybe was passed in to call-with-cached-connection. Which means no, I think it can be removed, at least that's more consistent with the older behaviour. I'll send some updated patches. > Regarding , I would lean towards > perhaps reverting the connection/error-handling patch series and > starting anew from that =E2=80=9Cknown state=E2=80=9D. > > This area is unfortunately quite tedious to test and to get right so I=E2= =80=99d > err on the path of conservative, incremental changes. > > Thought? My preference is still to try and move forward and to make the error handling easier to see in the code. Particularly with this change, I think the problem was introduced in this commit [1], but I think it's hard to tell from the diff, since the error handling and retrying is within with-cached-connection. 1: https://git.savannah.gnu.org/cgit/guix.git/commit/?id=3Df50f5751fff4cfc6= d5abba9681054569694b7a5c That commit was one of the commits where I was making small incremental changes prior to actually getting to the changes I was looking at making, but a breakage was still introduced. What I was thinking about with this patch was how to make the error handling being added back here easier to see, and thus harder to break/remove. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQKlBAEBCgCPFiEEPonu50WOcg2XVOCyXiijOwuE9XcFAmBPiARfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcRHG1haWxAY2Jh aW5lcy5uZXQACgkQXiijOwuE9XdzNhAAjlEXfQFwHMnKdBI6XW/16fih/rB9wMcA hkkHtvRyQQyEKkYaGBYhRcO/yYt5ovtjkT+FkcvWgA+MlOo9Fomk7eauyOIZcBA4 ibXRpfli5qvOvqSqr9Diu3lTiMYqIOAy1dG3iqYhbcQL+fNVJo5mI/FyMPSt3o5F EhRZJXeOn3wdV2KOWspRgIHpE43LJWGEiSJ6ISFrrvpHFBBL8Nu8K9nLa3vB+hFt s8tFMh6bityYCrlwHhS5cP0B2nenmI9BwZQzl+doB8I6N3hMfu7OdkUm/kNlqImQ 1MWOA/rYGrQNlj9XOGrefX4zQLyOSyfn3PcTcg4MqY8Az4WaaRmleIPyK5ZW4ikU /OQYBe5A6rz3HOtZxH7yYj8sEEWEWepSn5fwAxv+tAH5Ydpn8Iz91QGkHfty6ApM 6Gr+zn6g9CPvpVG/y16pvQx6nIFCrf5GJQcu8GgdZQn9/1dH/Fpa9KOYGis/X7hV 0rNYWaMq7/hcqA4nINS+JJSB6VSSXeh1+sxPh4GXuKxuev/UKjejfxGMaCZD4v7u LB+WR64S+tFE2frKS38PsXp1XmdmxSgEjTUBu0W+N/JbxpNb32o+XzZOWf1uS1dO VBEg/1WweBpTjQuHdi9TBb7Qhw6SvBK5kNBajwRq4JrdamNzyUm7QI7hzq/WZix9 xx6RtWXJjtw= =xoNb -----END PGP SIGNATURE----- --=-=-=--