From patchwork Tue May 3 11:42:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 39096 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5D66827BBEA; Tue, 3 May 2022 12:44:36 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id AC16C27BBE9 for ; Tue, 3 May 2022 12:44:35 +0100 (BST) Received: from localhost ([::1]:45690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlqxG-0003kG-Sa for patchwork@mira.cbaines.net; Tue, 03 May 2022 07:44:34 -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 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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")