From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id dD+wGeudXWDuZgAAgWs5BA (envelope-from ) for ; Fri, 26 Mar 2021 09:40:11 +0100 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 UBeBEuudXWCtbgAAbx9fmQ (envelope-from ) for ; Fri, 26 Mar 2021 08:40:11 +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 AC626332EC for ; Fri, 26 Mar 2021 09:40:10 +0100 (CET) Received: from localhost ([::1]:36274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPi0n-0001Rz-AC for larch@yhetil.org; Fri, 26 Mar 2021 04:40:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPi0g-0001Rt-PP for guix-patches@gnu.org; Fri, 26 Mar 2021 04:40:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lPi0g-0008BG-Go for guix-patches@gnu.org; Fri, 26 Mar 2021 04:40:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lPi0g-00051X-E7 for guix-patches@gnu.org; Fri, 26 Mar 2021 04:40:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47288] [PATCH] guix: http-client: Tweak http-multiple-get error handling. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 26 Mar 2021 08:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47288 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 47288@debbugs.gnu.org Received: via spool by 47288-submit@debbugs.gnu.org id=B47288.161674798819287 (code B ref 47288); Fri, 26 Mar 2021 08:40:02 +0000 Received: (at 47288) by debbugs.gnu.org; 26 Mar 2021 08:39:48 +0000 Received: from localhost ([127.0.0.1]:40332 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lPi0R-000511-S6 for submit@debbugs.gnu.org; Fri, 26 Mar 2021 04:39:48 -0400 Received: from mira.cbaines.net ([212.71.252.8]:36126) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lPi0P-00050s-HB for 47288@debbugs.gnu.org; Fri, 26 Mar 2021 04:39:46 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:8ac0:b4c7:f5c8:7caa]) by mira.cbaines.net (Postfix) with ESMTPSA id 841B027BC5C; Fri, 26 Mar 2021 08:39:44 +0000 (GMT) Received: from capella (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id 68faca7c; Fri, 26 Mar 2021 08:39:43 +0000 (UTC) References: <20210321004338.31867-1-mail@cbaines.net> <20210325110316.862-1-mail@cbaines.net> <87r1k250za.fsf_-_@gnu.org> User-agent: mu4e 1.4.15; emacs 27.1 From: Christopher Baines In-reply-to: <87r1k250za.fsf_-_@gnu.org> Date: Fri, 26 Mar 2021 08:39:41 +0000 Message-ID: <87h7ky9ulu.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=1616748010; 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=WmAUYb2sMtkKmDi/nJ2G8vtUtswbypZwBYpDeApULJI=; b=ACtbuD0WLpmuzulMJu7utFdrPBItG97NaMr28uQ76YkF06V0emT84txSxF1EU1Dqjsfilr keZDGJhN6HUH5ZJuW1/RNVV3m4kv0PY7RQV1uQQSOwZZlXPnilY0xfAojqmwKdQNqurAEO joa35Osc0pY1KwdXugO2K6QefALLcbZJteU9u+dWroT7Xq5Enpbthrs8zdwii8T35nJtN8 WnOXT67u/hwz0clduMd2VrlgyDj4J7BGIFEiq/30Th0DdLXHQ9Jeyvvaka8mbug8cWoL5N IC9yV7b3xusbBJW7z9CMyOeYSifzd2BtsZMFs3OwCkKUld9z5ec0Iq6wLnQZ9w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1616748010; a=rsa-sha256; cv=none; b=fLv9jhfJkD0S9ZwbfbFGTtPLol5SfeywtzVF3QujD1FqG9fi5NSALIJ9xD4W491j7EOlyD eCbug3grrI46X7SM1NtpRO36z15BWBlalHDWPCpEzdXxhtmHXT/vNO1bax6EkWpAhJj7NN ZhCoxEDxAPAznQPc9BiMqRVKV020exgQcVV39mCxpKtSggm2x8a9QCLjp+MbhRdBQkSLdg IcYp0KJw6d0jKHCKoYvMuCjdLJ0NOJXnO4Uf8CxFv0yu/RCw1C3iaZx8zpUu3KS3w9m485 /UOAlA+GNiwAy9PvIKNj3oahj8YGRZ7/cl+VTRsYYW3plaaXacm7Q86uJRSUEQ== 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.52 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: AC626332EC X-Spam-Score: -4.52 X-Migadu-Scanner: scn0.migadu.com X-TUID: +ACOHA1NlYxW --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s writes: > What about the approach below: > > diff --git a/guix/http-client.scm b/guix/http-client.scm > index 4b4c14ed0b..6351e2d051 100644 > --- a/guix/http-client.scm > +++ b/guix/http-client.scm > @@ -1,5 +1,5 @@ > ;;; GNU Guix --- Functional package management for GNU > -;;; Copyright =C2=A9 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020 Ludo= vic Court=C3=A8s > +;;; Copyright =C2=A9 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020, 202= 1 Ludovic Court=C3=A8s > ;;; Copyright =C2=A9 2015 Mark H Weaver > ;;; Copyright =C2=A9 2012, 2015 Free Software Foundation, Inc. > ;;; Copyright =C2=A9 2017 Tobias Geerinckx-Rice > @@ -147,6 +147,27 @@ Raise an '&http-get-error' condition if downloading = fails." > (uri->string uri) code > (response-reason-phrase resp)))))))))))) >=20=20 > +(define-syntax-rule (false-if-networking-error exp) > + "Return #f if EXP triggers a network related exception." > + ;; FIXME: Duplicated from 'with-cached-connection'. > + (catch #t > + (lambda () > + exp) > + (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) > + (=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-component))) > + #f > + (apply throw key args))))) > + > (define* (http-multiple-get base-uri proc seed requests > #:key port (verify-certificate? #t) > (open-connection guix:open-connection-for-ur= i) > @@ -219,42 +240,27 @@ returning." > (remainder > (connect p remainder result)))) > ((head tail ...) > - (catch #t > - (lambda () > - (let* ((resp (read-response p)) > - (body (response-body-port resp)) > - (result (proc head resp body result))) > - ;; The server can choose to stop responding at any time, > - ;; in which case we have to try again. Check whether > - ;; that is the case. Note that even upon "Connection: > - ;; close", we can read from BODY. > - (match (assq 'connection (response-headers resp)) > - (('connection 'close) > - (close-port p) > - (connect #f ;try again > - (drop requests (+ 1 processed)) > - result)) > - (_ > - (loop tail (+ 1 processed) result))))) ;keep going > - (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 respons= e) > - ;; 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 p) > - (connect #f ; try again > - (drop requests (+ 1 processed)) > - result)) > - (apply throw key args)))))))))) > + (match (false-if-networking-error (read-response p)) > + ((? response? resp) > + (let* ((body (response-body-port resp)) > + (result (proc head resp body result))) Given body is a port, and that port is passed to proc, I'm guessing it's possible for networking things to go wrong inside proc. > + ;; The server can choose to stop responding at any time, > + ;; in which case we have to try again. Check whether > + ;; that is the case. Note that even upon "Connection: > + ;; close", we can read from BODY. > + (match (assq 'connection (response-headers resp)) > + (('connection 'close) > + (close-port p) > + (connect #f ;try again > + (drop requests (+ 1 processed)) > + result)) > + (_ > + (loop tail (+ 1 processed) result))))) > + (#f > + (close-port p) > + (connect #f ; try again > + (drop requests (+ 1 processed)) I realised earlier in this series of patches that this should actually be processed, rather than (+ 1 processed) since proc can't have been run for the current response. > + result))))))))) >=20=20 > > ;;; > > I believe it=E2=80=99s a bit more readable because it moves =E2=80=98catc= h=E2=80=99 out of sight > and avoids the sort of =E2=80=9Cmini DSL=E2=80=9D where we return lists o= f arguments. > > WDYT? It looks OK to me, I think the only thing to figure out for sure is whether it's safe to not include the activity on the body port in the error handling. Thanks, Chris --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQKlBAEBCgCPFiEEPonu50WOcg2XVOCyXiijOwuE9XcFAmBdnc1fFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcRHG1haWxAY2Jh aW5lcy5uZXQACgkQXiijOwuE9XcABBAAl7UOhAkQGxDeOVP3ZAUoECJ2tb5FFhwB a1RCXVWCVWlFnOnikiA0h84zI9bM8yVDPuctdpKCEvUZRTUoaGDxSzK0GkC4i0C0 MpCXSo3uX+cFGjgaZ38WWUX8WbRizpdnnuE+VCAByzsVvmge6LyZqcn0w6GeGno8 TGYfXVsworVAxxjQi1VA7ZyEqfiBvCCJ9YkZwnfmGmrb6Qu1qSDT0z4GGrPWgEwW kkGtXxno0H1D1PKkwt9YrvqpiMXx1lHW7W6QGmQnuBK/kuIGhMq7fCgS50COxvAU pKOqOheOuBtiDC6eAYBG7tOlvwUNX4dTW2212wsEENx1qUqGl/imDu5AlLEDE5bt eZDBaxuOEYS9bPw/oUHeGgS5ys2ds5Enp61PSmQef/1nthPGrhEaxBBV6Yt4+zx9 Y8oRZnviA9bDGvcybI4UGidicAoAcP2Z4ri8HLS46aynEVzZlfATMiuZeihqnmix TXoGmY9+cqpJMyvaYIGuJye2AoRhkQ0BB7Ua9UqfUCuVeihSrWSa4KGWVMeqbvSJ M1r3O1xvaThV1ckN3+umTxfOtKb7/H8qPCEYQ7Srfmdg0wDcn/wvTsdM0iIebICR XXK/1mQyFARWUt2MPTrgOFbciDc06hNLnlcvQbHe63HIfw1zF7cBN+36g0IF0ty6 r8AwmsnO/oE= =ihh+ -----END PGP SIGNATURE----- --=-=-=--