all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Ricardo Wurmus <rekado@elephly.net>
Cc: Andy Wingo <wingo@igalia.com>, help-guix@gnu.org, 27476@debbugs.gnu.org
Subject: Re: bug#27476: guix pull fails on powerful server
Date: Thu, 12 Oct 2017 15:37:12 +0200	[thread overview]
Message-ID: <877ew0o5br.fsf@gnu.org> (raw)
In-Reply-To: <87shf44ny0.fsf@elephly.net> (Ricardo Wurmus's message of "Sat, 30 Sep 2017 09:59:03 +0200")

[-- Attachment #1: Type: text/plain, Size: 2151 bytes --]

Hi!

Ricardo Wurmus <rekado@elephly.net> skribis:

> The following derivation will be built:
>    /gnu/store/z5bhk17nxmdhvj0g4cy038p25mzh1gys-guix-latest.drv
> copying and compiling to '/gnu/store/s3s7xlqa10mvf8v0ypxz8gzw3lcf1x5z-guix-latest' with Guile 2.2.2...
> loading...       25.7% of 635 filesrandom seed for tests: 1506720257
> loading...       99.8% of 635 files
> compiling...     69.1% of 635 filesice-9/threads.scm:289:22: In procedure loop:
> ice-9/threads.scm:289:22: Syntax error:
> guix/scripts/graph.scm:103:10: return: return used outside of 'with-monad' in form (return (package-node-edges a))

The program below crashes with completely surreal backtraces in less
than a minute on my 4-thread laptop:

--8<---------------cut here---------------start------------->8---
(use-modules (ice-9 threads)
             (srfi srfi-1)
             (guix monads)
             (guix store))

(define threads
  (unfold (lambda (x) (> x 100))
          (lambda (x)
            (call-with-new-thread
             (lambda ()
               (define monad
                 (symbol-append 'foo-monad
                                (string->symbol (number->string x))))

               (while #t
                 (macroexpand
                  `(begin
                     (define-monad ,monad
                       (bind +)
                       (return -))
                     (with-monad ,monad
                       (return 3))
                     (mapm ,monad + '(1 2 3))))))))
          1+
          0))

(for-each join-thread threads)
--8<---------------cut here---------------end--------------->8---

Can you check if that also happens on your many-core machine?

The patch below seems to fix the problem: (guix monads) has shared state
(hash tables) used both at expansion-time and run-time, and it wasn’t
protected.

My hypothesis is that this was causing random memory corruption.  The
weird thing, though, is that the errors we were getting were not so
random.  Also, the load phase of ‘guix pull’ is sequential.

Could you test it and report back?

Thanks,
Ludo’.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 2527 bytes --]

diff --git a/guix/monads.scm b/guix/monads.scm
index 6ae616aca..c9c5da3bb 100644
--- a/guix/monads.scm
+++ b/guix/monads.scm
@@ -20,6 +20,7 @@
   #:use-module ((system syntax)
                 #:select (syntax-local-binding))
   #:use-module (ice-9 match)
+  #:use-module (ice-9 threads)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9)
   #:use-module (srfi srfi-26)
@@ -117,6 +118,7 @@
   ;; the syntax object of the parameter over which it is templated, and (2)
   ;; the syntax of its body.
   (define-once %templates (make-hash-table))
+  (define-once %template-lock (make-mutex))
 
   (define (register-template! name param body)
     (hash-set! %templates name (cons param body)))
@@ -139,8 +141,9 @@ template instances."
       (syntax-source s))
 
     (define current-info-port
-      ;; Port for debugging info.
-      (const (%make-void-port "w")))
+      ;; Port for debugging info.  Return a fresh port at each call to make
+      ;; sure we're thread-safe.
+      (lambda () (%make-void-port "w")))
 
     (define location-string
       (format #f "~a:~a:~a"
@@ -204,12 +207,14 @@ template instances."
        ;; Search for an instance of template NAME for this ACTUAL parameter.
        ;; On success, expand to the identifier of the instance; otherwise
        ;; expand to #f.
-       (any (matching-instance? #'name #'actual) %template-instances))
+       (with-mutex %template-lock
+         (any (matching-instance? #'name #'actual) %template-instances)))
       ((_ exists? name actual)
        ;; Likewise, but return a Boolean.
        (let ((result (->bool
-                      (any (matching-instance? #'name #'actual)
-                           %template-instances))))
+                      (with-mutex %template-lock
+                        (any (matching-instance? #'name #'actual)
+                             %template-instances)))))
          (unless result
            (format (current-warning-port)
                    "~a: warning: no specialization of template '~a' for '~a'~%"
@@ -220,8 +225,9 @@ template instances."
        ;; Expand to the definitions of all the existing templates
        ;; specialized for ACTUAL.
        #`(begin
-           #,@(hash-map->list (cut instance-definition <> <> #'actual)
-                              %templates))))))
+           #,@(with-mutex %template-lock
+                (hash-map->list (cut instance-definition <> <> #'actual)
+                                %templates)))))))
 
 (define-syntax define-template
   (lambda (s)

  parent reply	other threads:[~2017-10-12 13:37 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-22  8:38 guix pull fails on powerful server Ricardo Wurmus
2017-09-22 14:10 ` bug#27476: " Ludovic Courtès
2017-09-25  7:27   ` Andy Wingo
2017-09-25 13:03     ` Ludovic Courtès
2017-09-25 13:03     ` Ludovic Courtès
2017-09-25 14:02       ` bug#27476: " Ricardo Wurmus
2017-09-30  7:59         ` Ricardo Wurmus
2017-10-03 20:29           ` bug#27476: " Marius Bakke
2017-10-03 20:29           ` Marius Bakke
2017-10-04 13:15             ` Ricardo Wurmus
2017-10-04 13:15             ` bug#27476: " Ricardo Wurmus
2017-10-04 15:09           ` Clément Lassieur
2017-10-04 15:09           ` Clément Lassieur
2017-10-04 16:17             ` bug#27476: " Ricardo Wurmus
2017-10-07 15:11           ` Ludovic Courtès
2017-10-10  7:17             ` Ricardo Wurmus
2017-10-10 11:32               ` Ludovic Courtès
2017-10-10 11:32               ` bug#27476: " Ludovic Courtès
2017-10-10  7:17             ` Ricardo Wurmus
2017-10-07 15:11           ` Ludovic Courtès
2017-10-12 13:37           ` Ludovic Courtès [this message]
2017-10-13 20:29             ` Ricardo Wurmus
2017-10-13 20:29             ` Ricardo Wurmus
2017-10-13 21:04             ` Ricardo Wurmus
2017-10-13 21:10               ` Ricardo Wurmus
2017-10-12 13:37           ` Ludovic Courtès
2017-11-07 10:57           ` Ludovic Courtès
2017-11-07 10:57           ` Ludovic Courtès
2018-04-30 21:19             ` Ludovic Courtès
2018-04-30 21:39               ` bug#27476: libguile/memoize.c is not thread safe, so syntax parameter expansion is not thread-safe Ludovic Courtès
2018-05-09  8:41                 ` Andy Wingo
2018-05-09  9:23                   ` Ludovic Courtès
2018-05-09 10:18                     ` Andy Wingo
2019-02-06 14:48                       ` Ludovic Courtès
2019-02-06 16:14                         ` Andy Wingo
2019-02-06 22:09                           ` Ludovic Courtès
2019-01-29 10:07               ` bug#27476: guix pull fails on powerful server Ricardo Wurmus
2019-01-29 10:07               ` Ricardo Wurmus
2017-09-30  7:59         ` Ricardo Wurmus
2017-09-25  8:43 ` Clément Lassieur
2017-09-25  8:43 ` bug#27476: " Clément Lassieur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877ew0o5br.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=27476@debbugs.gnu.org \
    --cc=help-guix@gnu.org \
    --cc=rekado@elephly.net \
    --cc=wingo@igalia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.