Skip to content

Alpine: Package fails to load with 'Mutex creation failed' error #45

Closed

Description

@jpds

Hello,

I've tried building later in Alpine 3.7 and the testing stage fails with:

** testing if installed package can be loaded
terminate called after throwing an instance of 'std::runtime_error'
  what():  Mutex creation failed
Aborted (core dumped)
ERROR: loading failed

This can be reproduced with:

$ sudo docker pull alpine:3.7
$ sudo docker run --rm -it alpine:3.7
# apk add --no-cache R R-dev build-base
# R
> install.packages('later')

I'm installing this as it's a dependency for a shiny application which in turns depends on pool which I'm trying to run in Docker. Alpine uses https://www.musl-libc.org instead of the glibc commonly found in other Linux distributions.

I've also tried master with remotes::install_github("r-lib/later") and it has the same issue.

Activity

  1. fxi commented on Jun 4, 2018

    @fxi

    @jpds Have you found a solution or a workaround ?
    Thanks !

  2. svajiraya commented on Aug 1, 2018

    @svajiraya

    +1

  3. hcraT commented on Aug 7, 2018

    @hcraT

    I get the same error after an upgrade on arch linux (during which both glibc and gcc were upgraded).

  4. greenisagoodcolor commented on Aug 8, 2018

    @greenisagoodcolor

    Also getting the same error on arch linux. I dropped a reference on the R studio-desktop-bin thread on the AUR
    https://aur.archlinux.org/packages/rstudio-desktop-bin/#comment-657487

  5. znmeb commented on Aug 8, 2018

    @znmeb

    Yeah - Arch has the same problem. See https://bugs.archlinux.org/task/59550#comment171826 for the Arch package versions you need to downgrade.

  6. wch commented on Aug 8, 2018

    @wch
    Member

    If someone could provide a Dockerfile to reproduce the problem with Arch and/or Alpine, that would help to diagnose the problem.

  7. jcheng5 commented on Aug 8, 2018

    @jcheng5
    Member

    I wonder if this is because we're touching pthread from within a C++ static initializer.

  8. jcheng5 commented on Aug 8, 2018

    @jcheng5
    Member

    The bullet point with "Support for ISO C threads (ISO/IEC 9899:2011) has been added" is interesting. https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=NEWS;hb=HEAD

  9. grothja commented on Aug 8, 2018

    @grothja

    Should be good for Alpine debugging:

    FROM alpine
    
    RUN apk add --no-cache R R-dev R-doc build-base
    
    RUN R -e "install.packages(c('Rcpp', 'rlang', 'BH'), repos='https://cran.rstudio.com/')"
    
    RUN R -e "install.packages('later', repos='https://cran.rstudio.com/')" && \
        R -e "require('later')"
  10. znmeb commented on Aug 8, 2018

    @znmeb

    I've got a new bug open on Arch at https://bugs.archlinux.org/task/5958. I tried rebuilding R from R-patched source and installing learnr still crashed, but I want to rerun that test on a cleaner system before I go shouting to the world. ;-)

  11. jcheng5 commented on Aug 8, 2018

    @jcheng5
    Member

    I think I've narrowed it to the tinycthread library we're using. If you copy out tinycthread.* from our src dir, and compile/run the following, e.g. gcc -pthread test.c && ./a.out, it fails, while the same logic with a raw pthread mutex succeeds.

    #include <stdio.h>
    #include "tinycthread.h"
    
    int main() {
    	mtx_t mutex;
    	if (thrd_success != mtx_init(&mutex, mtx_plain | mtx_recursive)) {
    		fprintf(stderr, "Failed to create mutex\n");
    		return 1;
    	}
    	return 0;
    }
    

    Update: Actually it's working now, I think I was invoking the linker incorrectly.

  12. znmeb commented on Aug 9, 2018

    @znmeb

    Looks like I can reproduce this with R from source:

    1. Clean Antergos (Arch Linux) GNOME desktop install.
    2. # pacman -Syu r tk texlive-most gcc-fortran openblas ed biber.
    3. Start R and do install.packages('later').
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** installing vignettes
    ** testing if installed package can be loaded
    sh: line 1:  6519 Aborted                 (core dumped) '/usr/lib64/R/bin/R' --no-save --slave 2>&1 < '/tmp/RtmpdoIDxZ/file194e693060bf'
    terminate called after throwing an instance of 'std::runtime_error'
      what():  Mutex creation failed
    ERROR: loading failed
    * removing ‘/home/znmeb/R/x86_64-pc-linux-gnu-library/3.5/later’
    
    The downloaded source packages are in
    	‘/tmp/RtmpC43Icg/downloaded_packages’
    Warning message:
    In install.packages("later") :
      installation of package ‘later’ had non-zero exit status
    
    1. Uninistall R and install R-patched from CRAN source.
    2. Start R and do install.packages(c("Rcpp", "later")).
    $ R
    
    R version 3.5.1 Patched (2018-08-07 r75081) -- "Feather Spray"
    Copyright (C) 2018 The R Foundation for Statistical Computing
    Platform: x86_64-pc-linux-gnu (64-bit)
    
    R is free software and comes with ABSOLUTELY NO WARRANTY.
    You are welcome to redistribute it under certain conditions.
    Type 'license()' or 'licence()' for distribution details.
    
      Natural language support but running in an English locale
    
    R is a collaborative project with many contributors.
    Type 'contributors()' for more information and
    'citation()' on how to cite R or R packages in publications.
    
    Type 'demo()' for some demos, 'help()' for on-line help, or
    'help.start()' for an HTML browser interface to help.
    Type 'q()' to quit R.
    
    > install.packages(c("Rcpp", "later"))
    
    [snip]
    
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** installing vignettes
    ** testing if installed package can be loaded
    sh: line 1: 20163 Aborted                 (core dumped) '/usr/local/lib64/R/bin/R' --no-save --slave 2>&1 < '/tmp/RtmpzoQcDM/file4e991a4134a8'
    terminate called after throwing an instance of 'std::runtime_error'
      what():  Mutex creation failed
    ERROR: loading failed
    * removing ‘/home/znmeb/R/x86_64-pc-linux-gnu-library/3.5/later’
    
    The downloaded source packages are in
    	‘/tmp/RtmprdjabJ/downloaded_packages’
    Warning message:
    In install.packages(c("Rcpp", "later")) :
      installation of package ‘later’ had non-zero exit status
    > 
    

    Note that later is not the only package that's doing this. I don't have a complete list but at least learnr is failing.

    I've got a mostly clean install if there's anything else I should test. There's also another Arch bug on this issue - https://bugs.archlinux.org/task/59523.

  13. wch commented on Aug 9, 2018

    @wch
    Member

    Here's a Dockerfile for Arch that reproduces the problem. It also installs later by not doing a test load after installation:

    # Build:
    #  docker build -t archr .
    # Run:
    #  docker run --security-opt seccomp=unconfined --rm -ti archr
    
    FROM base/archlinux
    
    RUN pacman -Syu
    
    RUN pacman -Sy --noconfirm r git make gcc wget gdb vim
    
    RUN echo 'options(repos = c(CRAN = "https://cloud.r-project.org/"))' >> /usr/lib/R/etc/Rprofile.site
    
    # Compile with -O0 and debugging info
    RUN mkdir $HOME/.R \
      && echo -e "CFLAGS += -g -O0 -Wall\nCXXFLAGS += -g -O0 -Wall\nCXX11FLAGS += -g -O0 -Wall" > $HOME/.R/Makevars
    
    RUN R -e 'install.packages(c("Rcpp", "rlang", "BH"))'
    
    RUN git clone https://github.com/r-lib/later.git
    RUN R CMD build --no-build-vignettes later 
    RUN R CMD INSTALL --no-test-load later_0.7.3.tar.gz
    

    After building it, these commands will run a docker container, start R, and load the package, leading to the crash. (The seccomp=unconfined part is there so that gdb will work in the container.)

    docker run --security-opt seccomp=unconfined --rm -ti archr
    R -d gdb
    run
    library(later)
    

    Here's the output that I got from doing that:

    > library(later)
    terminate called after throwing an instance of 'std::runtime_error'
      what():  Mutex creation failed
    
    Program received signal SIGABRT, Aborted.
    0x00007ffff798fb5f in raise () from /usr/lib/libc.so.6
    (gdb) bt
    #0  0x00007ffff798fb5f in raise () from /usr/lib/libc.so.6
    #1  0x00007ffff797a452 in abort () from /usr/lib/libc.so.6
    #2  0x00007ffff3a7258e in __gnu_cxx::__verbose_terminate_handler ()
        at /build/gcc/src/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
    #3  0x00007ffff3a78dfa in __cxxabiv1::__terminate(void (*)()) ()
        at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:47
    #4  0x00007ffff3a78e57 in std::terminate ()
        at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:57
    #5  0x00007ffff3a790ac in __cxxabiv1::__cxa_throw (obj=<optimized out>, 
        tinfo=0x7ffff3b6b050 <typeinfo for std::runtime_error>, 
        dest=0x7ffff3a8ebe0 <std::runtime_error::~runtime_error()>)
        at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:95
    #6  0x00007ffff2e14fd9 in Mutex::Mutex (this=0x7ffff2e296c0 <callbackRegistry+32>, type=8)
        at threadutils.h:40
    #7  0x00007ffff2e13f64 in CallbackRegistry::CallbackRegistry (
        this=0x7ffff2e296a0 <callbackRegistry>) at callback_registry.cpp:7
    #8  0x00007ffff2e192c3 in __static_initialization_and_destruction_0 (__initialize_p=1, 
        __priority=65535) at later.cpp:74
    #9  0x00007ffff2e192fa in _GLOBAL__sub_I_later.cpp(void) () at later.cpp:159
    #10 0x00007ffff7fe36da in call_init.part () from /lib64/ld-linux-x86-64.so.2
    #11 0x00007ffff7fe37da in _dl_init () from /lib64/ld-linux-x86-64.so.2
    #12 0x00007ffff7fe76c3 in dl_open_worker () from /lib64/ld-linux-x86-64.so.2
    #13 0x00007ffff7a8fcd7 in _dl_catch_exception () from /usr/lib/libc.so.6
    #14 0x00007ffff7fe6f8f in _dl_open () from /lib64/ld-linux-x86-64.so.2
    #15 0x00007ffff683014a in ?? () from /usr/lib/libdl.so.2
    #16 0x00007ffff7a8fcd7 in _dl_catch_exception () from /usr/lib/libc.so.6
    #17 0x00007ffff7a8fd73 in _dl_catch_error () from /usr/lib/libc.so.6
    #18 0x00007ffff68308af in ?? () from /usr/lib/libdl.so.2
    #19 0x00007ffff68301ea in dlopen () from /usr/lib/libdl.so.2
    #20 0x00007ffff7bb1fa6 in ?? () from /usr/lib64/R/lib/libR.so
    #21 0x00007ffff7bb2320 in ?? () from /usr/lib64/R/lib/libR.so
    #22 0x00007ffff7c6d6d7 in ?? () from /usr/lib64/R/lib/libR.so
    #23 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #24 0x00007ffff7c7f640 in ?? () from /usr/lib64/R/lib/libR.so
    #25 0x00007ffff7c74462 in ?? () from /usr/lib64/R/lib/libR.so
    #26 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #27 0x00007ffff7c7f640 in ?? () from /usr/lib64/R/lib/libR.so
    #28 0x00007ffff7c74462 in ?? () from /usr/lib64/R/lib/libR.so
    #29 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #30 0x00007ffff7c7f640 in ?? () from /usr/lib64/R/lib/libR.so
    #31 0x00007ffff7c74462 in ?? () from /usr/lib64/R/lib/libR.so
    #32 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #33 0x00007ffff7c7e2ff in ?? () from /usr/lib64/R/lib/libR.so
    #34 0x00007ffff7c7e808 in ?? () from /usr/lib64/R/lib/libR.so
    #35 0x00007ffff7c72e0d in ?? () from /usr/lib64/R/lib/libR.so
    #36 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #37 0x00007ffff7c7e2ff in ?? () from /usr/lib64/R/lib/libR.so
    #38 0x00007ffff7c7e808 in ?? () from /usr/lib64/R/lib/libR.so
    #39 0x00007ffff7c72e0d in ?? () from /usr/lib64/R/lib/libR.so
    #40 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #41 0x00007ffff7c7e2ff in ?? () from /usr/lib64/R/lib/libR.so
    #42 0x00007ffff7c7e808 in ?? () from /usr/lib64/R/lib/libR.so
    #43 0x00007ffff7c72e0d in ?? () from /usr/lib64/R/lib/libR.so
    #44 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #45 0x00007ffff7c7e2ff in ?? () from /usr/lib64/R/lib/libR.so
    #46 0x00007ffff7c7e808 in ?? () from /usr/lib64/R/lib/libR.so
    #47 0x00007ffff7c72e0d in ?? () from /usr/lib64/R/lib/libR.so
    #48 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #49 0x00007ffff7c7f640 in ?? () from /usr/lib64/R/lib/libR.so
    #50 0x00007ffff7c74462 in ?? () from /usr/lib64/R/lib/libR.so
    #51 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #52 0x00007ffff7c7f640 in ?? () from /usr/lib64/R/lib/libR.so
    #53 0x00007ffff7c74462 in ?? () from /usr/lib64/R/lib/libR.so
    #54 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #55 0x00007ffff7c7f640 in ?? () from /usr/lib64/R/lib/libR.so
    #56 0x00007ffff7c74462 in ?? () from /usr/lib64/R/lib/libR.so
    #57 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #58 0x00007ffff7c7f640 in ?? () from /usr/lib64/R/lib/libR.so
    #59 0x00007ffff7c74462 in ?? () from /usr/lib64/R/lib/libR.so
    #60 0x00007ffff7c7d980 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #61 0x00007ffff7c7f640 in ?? () from /usr/lib64/R/lib/libR.so
    #62 0x00007ffff7c7db39 in Rf_eval () from /usr/lib64/R/lib/libR.so
    #63 0x00007ffff7caead6 in Rf_ReplIteration () from /usr/lib64/R/lib/libR.so
    #64 0x00007ffff7caeea2 in ?? () from /usr/lib64/R/lib/libR.so
    #65 0x00007ffff7caef59 in run_Rmainloop () from /usr/lib64/R/lib/libR.so
    #66 0x000055555555503d in main ()
    
    
  14. znmeb commented on Aug 9, 2018

    @znmeb

    Will the system function if you install later with "--no-test-load"?

  15. 2 remaining items

  16. znmeb commented on Aug 9, 2018

    @znmeb

    I found another case where there's a mutex issue - learnr. See rstudio/learnr#178. That one croaks at compile time.

    I think that's all of them - I'm running my package install scripts to see if anything else shakes out.

  17. wch commented on Aug 9, 2018

    @wch
    Member

    @jcheng5 The fact that your C test program successfully compiled and linked indicates that it's using mtx_init from somewhere other than tinycthread.c.

    This is the program:

    #include <stdio.h>
    #include "tinycthread.h"
    
    int main() {
    	mtx_t mutex;
    	if (thrd_success != mtx_init(&mutex, mtx_plain | mtx_recursive)) {
    		fprintf(stderr, "Failed to create mutex\n");
    		return 1;
    	}
    	return 0;
    }

    This is the compile command:

    gcc -pthread test.c
    

    So even though the source file included tinycthread.h, the gcc command did not compile tinycthread.c or link to the nonexistent tinycthread.o file. Still, it managed to link to something and created a working executable.

    When I try to compile the same program with the same command on my Mac, I get:

    $ gcc -pthread test.c
    Undefined symbols for architecture x86_64:
      "_mtx_init", referenced from:
          _main in test-9394ac.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    And on Ubuntu 18.04:

    # gcc -pthread test.c
    /tmp/ccu2povH.o: In function `main':
    test.c:(.text+0x24): undefined reference to `mtx_init'
    collect2: error: ld returned 1 exit status
    
  18. loqs commented on Aug 9, 2018

    @loqs

    @znmeb if you apply this test patch does that resolve the issue for all packages?
    I suspect all the other packages you have issues with are as a result of depending on later.

    diff --git a/src/threadutils.h b/src/threadutils.h
    index fb9e7ad..279e957 100644
    --- a/src/threadutils.h
    +++ b/src/threadutils.h
    @@ -7,7 +7,6 @@
     #include <boost/type_traits/is_integral.hpp>
     #include <boost/type_traits/is_signed.hpp>
     
    -#include "tinycthread.h"
     #include "timeconv.h"
     
     #ifndef CLOCK_REALTIME
    @@ -133,7 +132,7 @@ public:
         int res = cnd_timedwait(&_c, _m, &ts);
         if (res == thrd_success) {
           return true;
    -    } else if (res == thrd_timeout) {
    +    } else if (res == thrd_timedout) {
           return false;
         } else {
           throw std::runtime_error("Condition variable failed to timedwait");
    diff --git a/src/timeconv.h b/src/timeconv.h
    index 01103ae..199c717 100644
    --- a/src/timeconv.h
    +++ b/src/timeconv.h
    @@ -3,7 +3,7 @@
     // tinycthread.h to provide timespec. Whether tinycthread
     // defines timespec or not, we want it to be consistent for
     // anyone who uses these functions.
    -#include "tinycthread.h"
    +#include <threads.h>
     
     inline timespec timevalToTimespec(const timeval& tv) {
       timespec ts;
  19. jcheng5 commented on Aug 9, 2018

    @jcheng5
    Member

    Thank you to all of you on this thread for all of the great info, and for your continued patience as we sort this all out.

    To sum up the issue, we use a threading library, tinycthread, as a polyfill for C11 threads. Now that glibc implements C11 threads, the compiler is using the functions defined in tinycthread.h but the linker is finding their implementations in libpthread. @wch is working on a fix to use threads.h if it's available, only falling back to tinycthread if necessary.

  20. znmeb commented on Aug 9, 2018

    @znmeb

    Note for Arch Linux users - all of the open "tasks" (their word for bugs) relating to this issue have been closed.

  21. wch commented on Aug 10, 2018

    @wch
    Member

    We just merged a fix into master. For everyone who has experienced a problem, can you test and report back with how it works, and the platform you're on?

    devtools::install_github("r-lib/later")
  22. loqs commented on Aug 10, 2018

    @loqs

    Arch Linux with glibc 2.28 no issues with 3a41561

  23. sanjmeh commented on Feb 4, 2019

    @sanjmeh

    I got the same error without even packages later or learnr

    "terminate called after throwing an instance of 'std::runtime_error'

    This came on a small shiny package on an ubuntu server when invoked from a client browser.
    If you need I can send a replicable code. But if this has been already fixed and the code is not on cran, kindly let me know if I should install shiny from source.

  24. msberends commented on Mar 21, 2019

    @msberends

    Same here:

    * installing *source* package ‘htmlwidgets’ ...
    ** package ‘htmlwidgets’ successfully unpacked and MD5 sums checked
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    terminate called after throwing an instance of 'std::runtime_error'
      what():  Mutex creation failed
    Aborted
    Warning in install.packages :
      installation of package ‘htmlwidgets’ had non-zero exit status
    
    * installing *source* package ‘shiny’ ...
    ** package ‘shiny’ successfully unpacked and MD5 sums checked
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    terminate called after throwing an instance of 'std::runtime_error'
      what():  Mutex creation failed
    
    # and here on and on and on
    

    Not sure how this is connected to #63 btw, but it is an annoying problem, roughly 50% of my packages fail to install because of this (today 14 out of 30).

  25. wch commented on Mar 21, 2019

    @wch
    Member

    @msberends this was fixed a while back. What version of later are you trying to install?

  26. msberends commented on Mar 22, 2019

    @msberends

    I’m not, I get this error while installing shiny and related packages.
    Just as the user comment above mine.

    I googled and stackoverflow-ed the error, but can’t find any clue. Do you perhaps happen to know what the error means?

  27. jcheng5 commented on Mar 22, 2019

    @jcheng5
    Member

    @msberends Can you try install.packages("later"), then try installing shiny again?

  28. jcheng5 commented on Mar 22, 2019

    @jcheng5
    Member

    Oh actually, before you do that, tell us what packageVersion("later") says, then try installing later?

  29. msberends commented on Mar 23, 2019

    @msberends

    packageVersion("later") returned 0.7.5. I don’t get it, RStudio said all other packages where up to date ?!

    After this, later 0.8.0 got installed and all worked fine! Thank you so much!! Sorry for bothering you 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions