From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id SEN+D6UVcWIqkAAAbAwnHQ (envelope-from ) for ; Tue, 03 May 2022 13:44:37 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id aLt3D6UVcWKy1AAAauVa8A (envelope-from ) for ; Tue, 03 May 2022 13:44:37 +0200 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 D74E71EEE5 for ; Tue, 3 May 2022 13:44:36 +0200 (CEST) Received: from localhost ([::1]:45690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlqxH-0003kG-U1 for larch@yhetil.org; Tue, 03 May 2022 07:44:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlqwm-0003eo-TL for guix-patches@gnu.org; Tue, 03 May 2022 07:44:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:44945) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlqwm-0002Rr-GW for guix-patches@gnu.org; Tue, 03 May 2022 07:44:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nlqwm-0005QR-Eb for guix-patches@gnu.org; Tue, 03 May 2022 07:44:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55242] [PATCH 07/10] guix: import: go: More resilience wrt network errors; add logging. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 03 May 2022 11:44:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55242 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55242@debbugs.gnu.org Cc: Attila Lendvai Received: via spool by 55242-submit@debbugs.gnu.org id=B55242.165157821720761 (code B ref 55242); Tue, 03 May 2022 11:44:04 +0000 Received: (at 55242) by debbugs.gnu.org; 3 May 2022 11:43:37 +0000 Received: from localhost ([127.0.0.1]:38831 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nlqwI-0005OX-6f for submit@debbugs.gnu.org; Tue, 03 May 2022 07:43:37 -0400 Received: from mail-ed1-f50.google.com ([209.85.208.50]:45616) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nlqwF-0005NB-8X for 55242@debbugs.gnu.org; Tue, 03 May 2022 07:43:31 -0400 Received: by mail-ed1-f50.google.com with SMTP id be20so19512278edb.12 for <55242@debbugs.gnu.org>; Tue, 03 May 2022 04:43:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SuK3B+RxJ2ghmZTZHTJv8kAsn1424PMUiNz8KrpJG4M=; b=A8ttGQFo4n4VYV/taagFKkrGYY5sqKLMPIveuHnanfytuV0YmGbCSUSwE+wAVYemXQ 6rs8mJZG3LIJKfBR/XJPi2ekcfecjbWPCKoYX9upfVlmuEaSRoGnH3P083Z+Gx9Oi2UI SJ7jQ6c9IsuOjmz9aPMRWi2xnwIUgiEmsYNQgySn+tmDdg7bsRwDPSzlKhBON/ZMQxC/ pxYVwT7mqz/r4m+sHlHORTkXqZuC3EkCqQDNSaY3OD/Oi0/kTBseT4FmvOgshPoF+zE5 I0Ixh0rYpPi3fA9D72qcdyIlhYGdnPCf5UKQCVREfkNbyLu58rbkx0IZ1KZwVjpz3Kjb 6mkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=SuK3B+RxJ2ghmZTZHTJv8kAsn1424PMUiNz8KrpJG4M=; b=lO+xY0bhcCKbo8JWfwCwEdCpBTiyH6sWouVPMrOuOwnB+c6d1uW4yMbc9iJpILPN/L 0w87ccbtTOImvuO3YMbapc0qBFdniTUQRtq/Ast1/CO4sQKhzcjckROfT/HJpdHlbKAL hmIzeEn/lK8VFUsqu3eeI+qZhlK2PQtpUQnTN0VtuUCNCub6MyyGevf3og31UnjQBGok 34t1ZA+YMmY4XIb/ho839+gOqsdqUb/lROP9IiKAJy1qy6Gr/DAM4edpqlKonuM0czqC soKb4p/e2QTn3j94uAqL9+HDsYwdlIyPg2NiB91VSsPrshmTqk2VosiZh5Ejk+3yyPdq w6xg== X-Gm-Message-State: AOAM5339sK/cKBwcEi2TbQQ1R0rT7boiViE8YWfLWw0TsxsAcGq26omp rxsXnCuTKbUA/Mgj0JDH1aVbVxGNnQo= X-Google-Smtp-Source: ABdhPJxJLe04AocUpwUcav0J5DP9XDhmJEq8HZevXD0vKIKCAa078b5N+/7aaSActZe9oBna8VfUZQ== X-Received: by 2002:a05:6402:35d3:b0:427:b3c7:f7f2 with SMTP id z19-20020a05640235d300b00427b3c7f7f2mr13231077edc.152.1651578205583; Tue, 03 May 2022 04:43:25 -0700 (PDT) Received: from lelap.local (catv-89-132-245-188.catv.fixed.vodafone.hu. [89.132.245.188]) by smtp.gmail.com with ESMTPSA id k13-20020a05640212cd00b0042617ba63d6sm7766964edx.96.2022.05.03.04.43.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 04:43:25 -0700 (PDT) From: Attila Lendvai Date: Tue, 3 May 2022 13:42:58 +0200 Message-Id: <20220503114301.9524-7-attila@lendvai.name> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220503114301.9524-2-attila@lendvai.name> References: <20220503114301.9524-2-attila@lendvai.name> 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 X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1651578277; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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:dkim-signature; bh=SuK3B+RxJ2ghmZTZHTJv8kAsn1424PMUiNz8KrpJG4M=; b=flsnoUKgfSFMDIO2kG9A/7g5E1ofa69ZPMj78UyLfV9/60AAumic5I3lKRjCUj91ITvMCf tQ3WZJPjMByvcrBYM0fy/Cvz51/9gmSA4HResetBc87VXLKLBCjITAGWoIIZ/6uiNX0Pb+ lJz0oU4Rhll3OQisinjywBvEQUkivS/DXgrz1yIiqR83RYVc1kP8zFCCP6fXFsUKNLtcXe C9XA8+ElKbHJ0IyV8YkclFoGHjlPmPUcIhfhcaJkwK+egZrxf63GyKKCqpffdCD3DN6jQb XDf1IYJtUUiT8327wiweYiiz0EJyHC0p1BZbV+stZvC6ysfVxufF9GGoO2Zrtw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1651578277; a=rsa-sha256; cv=none; b=lHu3f6onA5agIyd+qqraRb/YfBxRx11KGClNMue8In7/pwb7ei6uTijay5/CWNxdjzJgeP rSxOsDxC29SEKaj0CufDVz7b61i0R1F8KbUivdUdELqGvMrjAvG3OGbzk9u0iDglNhnhVO B8mj0Dt1C/q1Gcdm2FgpEuW3nKJ/j0L1VEEtVf/E1OkeWrc89+d+08CGOkcVQed+YouV5w NvpLIIBqm+DcQBTL5HnJkejLdGooDWuS4jtEqE2TCutX4K4pd9nAENb9t0TSgFKSOkRRLK yj+w3dEboJtgbHB1IqD2XsuEKWZpBGJzmuqSmvcfinSyU46uEv8/LaqCXwL/qQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=A8ttGQFo; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 1.52 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=A8ttGQFo; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: D74E71EEE5 X-Spam-Score: 1.52 X-Migadu-Scanner: scn0.migadu.com X-TUID: S3UDARwWR+fh This also adds logging statements to various parts of the go importer. * guix/import/go.scm (go-module->guix-package*): Catch exceptions and retry in case of network errors. Add ability to enable printing a full backtrace when debugging. (go-module->guix-package): Tolerate the inability to fetch the synopsis and description. --- guix/import/go.scm | 104 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 18 deletions(-) diff --git a/guix/import/go.scm b/guix/import/go.scm index a08005d090..6871132a70 100644 --- a/guix/import/go.scm +++ b/guix/import/go.scm @@ -23,7 +23,15 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . +;;; goproxy protocol: +;;; https://golang.org/ref/mod#module-proxy +;;; https://docs.gomods.io/intro/protocol/ +;;; https://roberto.selbach.ca/go-proxies/ + (define-module (guix import go) + #:use-module (git) + #:use-module (git structs) + #:use-module (git errors) #:use-module (guix build-system go) #:use-module (guix git) #:use-module (guix hash) @@ -51,6 +59,8 @@ (define-module (guix import go) #:autoload (guix build utils) (mkdir-p dump-port) #:autoload (gcrypt hash) (hash-algorithm sha256) #:use-module (ice-9 format) + #:use-module (ice-9 control) + #:use-module (ice-9 exceptions) #:use-module (ice-9 match) #:use-module (ice-9 peg) #:use-module (ice-9 rdelim) @@ -629,10 +639,14 @@ (define (go-import->module-meta content-text) (make-module-meta root-path (string->symbol vcs) (strip-.git-suffix/maybe repo-url))))) ;; - (let* ((meta-data (http-fetch* (format #f "https://~a?go-get=1" module-path))) + (let* ((url (format #f "https://~a?go-get=1" module-path)) + (meta-data (http-fetch* url #:accept-all-response-codes? #true)) (select (sxpath `(// (meta (@ (equal? (name "go-import")))) - // content)))) - (match (select (html->sxml meta-data #:strict? #t)) + // content))) + (sxml (html->sxml meta-data #:strict? #t)) + (selected (select sxml))) + (log.debug "The fetched meta-data from ~A is:~%~S" url selected) + (match selected (() #f) ;nothing selected ((('content content-text) ..1) (or @@ -809,22 +823,76 @@ (define* (go-module->guix-package module-path #:key dependencies+versions dependencies)))) -(define go-module->guix-package* - (lambda args - ;; Disable output buffering so that the following warning gets printed - ;; consistently. - (setvbuf (current-error-port) 'none) - (let ((package-name (match args ((name _ ...) name)))) - (guard (c ((http-get-error? c) - (warning (G_ "Failed to import package ~s. -reason: ~s could not be fetched: HTTP error ~a (~s). +(define (go-module->guix-package* . args) + ;; Disable output buffering so that the following warning gets printed + ;; consistently. + (setvbuf (current-error-port) 'none) + (setvbuf (current-warning-port) 'none) + (let* ((package-name (match args ((name _ ...) name))) + ;; Use report-all-errors? for debugging purposes only, because + ;; e.g. getaddrinfo is not reentrant and therefore we must unwind + ;; before retrying. + (report-all-errors? #false) + (report-network-error + (lambda (reason) + (warning (G_ "Failing to import package ~S. +reason: ~A.~%") + package-name reason)))) + (let loop ((attempts 0)) + (when (> attempts 0) + (sleep 3) + (log.info "~%Retrying, attempt ~s." attempts)) + (cond + ((> attempts 60) + (warning (G_ "Giving up on importing package ~s. This package and its dependencies won't be imported.~%") - package-name - (uri->string (http-get-error-uri c)) - (http-get-error-code c) - (http-get-error-reason c)) - (values #f '()))) - (apply go-module->guix-package args))))) + package-name) + (values #f '())) + (else + (guard (c ((http-get-error? c) + (report-network-error + (format #f "~s could not be fetched: HTTP error ~a (~s)" + (uri->string (http-get-error-uri c)) + (http-get-error-code c) + (http-get-error-reason c))) + (loop (+ 1 attempts))) + ((eq? (exception-kind c) + 'getaddrinfo-error) + (report-network-error "DNS lookup failed") + (loop (+ 1 attempts))) + ((and (eq? (exception-kind c) + 'git-error) + (eq? (git-error-class (first (exception-args c))) + GITERR_NET)) + (report-network-error "network error coming from git") + (loop (+ 1 attempts))) + (else + (let ((port (current-warning-port))) + (format port "Unexpected error, will skip ~S.~%reason: " + package-name) + ;; Printing a backtrace here is not very useful: it is + ;; cut off because GUARD unwinds. + (print-exception port (stack-ref (make-stack #t) 1) + c (exception-args c)) + (display-backtrace (make-stack #t) port)) + ;; give up on this entry + (values #f '()))) + (with-exception-handler + (lambda (c) + (when report-all-errors? + (let ((port (current-warning-port))) + (format port "*** exception while importing:~%") + (print-exception port (stack-ref (make-stack #t) 1) + c (exception-args c)) + (format port "*** printing backtrace:~%") + (display-backtrace (make-stack #t) port) + ;; DISPLAY-BACKTRACE can fail, so it's better to make its + ;; exit also visible. + (format port "*** done printing backtrace~%"))) + (raise-continuable c)) + (lambda () + (apply go-module->guix-package args)) + #:unwind? (not report-all-errors?)))))))) (define* (go-module-recursive-import package-name #:key (goproxy "https://proxy.golang.org") -- 2.35.1