Calling ‘texi-fragment->stexi’ in parallel leads to crashes

  • Done
  • quality assurance status badge
Details
One participant
  • Ludovic Courtès
Owner
unassigned
Submitted by
Ludovic Courtès
Severity
important
L
L
Ludovic Courtès wrote on 18 Oct 2021 14:54
(address . bug-guile@gnu.org)
87pms2a3yd.fsf@inria.fr
Hello!

I just stumbled upon this bug (here I use Guix to feed Texinfo strings
but I suppose we could reduce the test case to be Guix-less.)

Test case:
(use-modules (guix) (gnu) (texinfo) (ice-9 threads)) (define sequential? (getenv "SEQUENTIAL")) (define (for-each/maybe-parallel proc lst) (if (pk 'sequential? sequential?) (for-each proc lst) (n-par-for-each 10 proc lst))) (for-each/maybe-parallel (lambda (package) (and=> (package-description package) (lambda (str) (catch 'parser-error (lambda () (texi-fragment->stexi str)) (lambda args (pk 'bah! args) (error "failed")))))) (fold-packages cons '()))
This code crashes when using ‘n-par-for-each’ but passes when run
sequentially:

Toggle snippet (47 lines)
$ guix time-machine --commit=9cda21cf20a5c9bdf97e3a6d6c8f901fc3e4307d -- repl -- bug-texi-parser-parallel.scm

;;; (sequential? #f)

;;; (bah! (parser-error #f "Unknown command" codeand))
In thread:
failed

;;; (bah! (parser-error #f "Unknown command" endm))
In thread:
failed

;;; (bah! (parser-error #f "Unknown command" cod))
In thread:
failed

;;; (bah! (parser-error #f "Unknown command" comm))
In thread:
failed

;;; (bah! (parser-error #f "Unknown command" enum))
In thread:
failed

;;; (bah! (parser-error #f "Unknown command" cod))
In thread:
failed

;;; (bah! (parser-error #f "Unknown command" enem))
In thread:
failed


;;; (bah! (parser-error #f "Unknown command" endmand))
In thread:
failed
;;;;; (bah! (parser-error #f "Unknown command" eomm))
In thread:
failed
$ SEQUENTIAL=y guix time-machine --commit=9cda21cf20a5c9bdf97e3a6d6c8f901fc3e4307d -- repl -- bug-texi-parser-parallel.scm

;;; (sequential? "y")
$ guix repl -- <(echo '(pk (version))')

;;; ("3.0.7")

The bits shown in the ‘parser-error’ arguments suggests memory
corruption.

Ludo’.
L
L
Ludovic Courtès wrote on 18 Oct 2021 17:50
control message for bug #51264
(address . control@debbugs.gnu.org)
87o87m9vrx.fsf@gnu.org
severity 51264 important
quit
L
L
Ludovic Courtès wrote on 22 Oct 2021 13:56
Re: bug#51264: Calling ‘texi-fragment->stexi ’ in parallel leads to crashes
(address . 51264-done@debbugs.gnu.org)
87v91ptgrd.fsf@gnu.org
Ludovic Courtès <ludo@gnu.org> skribis:

Toggle quote (3 lines)
> I just stumbled upon this bug (here I use Guix to feed Texinfo strings
> but I suppose we could reduce the test case to be Guix-less.)

Here’s a standalone reproducer:
(use-modules (texinfo) (sxml simple) (ice-9 threads)) (define sequential? (getenv "SEQUENTIAL")) (define (for-each/maybe-parallel proc lst) (if (pk 'sequential? sequential?) (for-each proc lst) (n-par-for-each 6 proc lst))) (setvbuf (current-output-port) 'none) (for-each/maybe-parallel (lambda (str) (catch 'parser-error (lambda () (texi-fragment->stexi str)) (lambda args (pk 'bah! args '<<>> str) (error "failed")))) (make-list 5000 "Hello @code{world}, this is @emph{Texinfo}."))
It turned out that (sxml ssax input-parse) would reuse the same global
buffer for each call to ‘next-token’ and ‘next-token-of’ (the Texinfo
parser uses the latter).

Fixed in 3b42b1eb526a85e4fac772e1837046e56e3b9bdc.

Ludo’.
Closed
?