You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Alpine: Package fails to load with 'Mutex creation failed' error #45
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've also tried master with remotes::install_github("r-lib/later") and it has the same issue.
Reacted by Jack Grahl, Jonathan Groth, Andrei Karshkov, Artem Klevtsov, F.Moser, Mark Sellors, Arghya Sarkar, Pierre Formont, hcraT, Tim Zhou and 1 more
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')"
Reacted by Winston Chang, Antony Denyer and Joe Cheng
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.
# pacman -Syu r tk texlive-most gcc-fortran openblas ed biber.
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
Uninistall R and install R-patched from CRAN source.
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.
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 ()
@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"intmain() {
mtx_tmutex;
if (thrd_success!=mtx_init(&mutex, mtx_plain | mtx_recursive)) {
fprintf(stderr, "Failed to create mutex\n");
return1;
}
return0;
}
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
@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;
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.
Reacted by Wesley A and Buck Borasky, Frontier Programmer
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?
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.
* 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).
Activity
jpds commentedon Mar 2, 2018
Actually, this seems to be coming from: https://github.com/r-lib/later/blob/master/src/threadutils.h#L38
fxi commentedon Jun 4, 2018
@jpds Have you found a solution or a workaround ?
Thanks !
svajiraya commentedon Aug 1, 2018
+1
hcraT commentedon Aug 7, 2018
I get the same error after an upgrade on arch linux (during which both glibc and gcc were upgraded).
greenisagoodcolor commentedon Aug 8, 2018
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
znmeb commentedon Aug 8, 2018
Yeah - Arch has the same problem. See https://bugs.archlinux.org/task/59550#comment171826 for the Arch package versions you need to downgrade.
wch commentedon Aug 8, 2018
If someone could provide a Dockerfile to reproduce the problem with Arch and/or Alpine, that would help to diagnose the problem.
jcheng5 commentedon Aug 8, 2018
I wonder if this is because we're touching pthread from within a C++ static initializer.
jcheng5 commentedon Aug 8, 2018
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
grothja commentedon Aug 8, 2018
Should be good for Alpine debugging:
znmeb commentedon Aug 8, 2018
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
learnrstill crashed, but I want to rerun that test on a cleaner system before I go shouting to the world. ;-)jcheng5 commentedon Aug 8, 2018
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.Update: Actually it's working now, I think I was invoking the linker incorrectly.
znmeb commentedon Aug 9, 2018
Looks like I can reproduce this with R from source:
# pacman -Syu r tk texlive-most gcc-fortran openblas ed biber.install.packages('later').install.packages(c("Rcpp", "later")).Note that
lateris not the only package that's doing this. I don't have a complete list but at leastlearnris 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.
wch commentedon Aug 9, 2018
Here's a Dockerfile for Arch that reproduces the problem. It also installs later by not doing a test load after installation:
After building it, these commands will run a docker container, start R, and load the package, leading to the crash. (The
seccomp=unconfinedpart is there so thatgdbwill work in the container.)Here's the output that I got from doing that:
znmeb commentedon Aug 9, 2018
Will the system function if you install
laterwith "--no-test-load"?2 remaining items
znmeb commentedon Aug 9, 2018
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.
wch commentedon Aug 9, 2018
@jcheng5 The fact that your C test program successfully compiled and linked indicates that it's using
mtx_initfrom somewhere other thantinycthread.c.This is the program:
This is the compile command:
So even though the source file included
tinycthread.h, thegcccommand did not compiletinycthread.cor link to the nonexistenttinycthread.ofile. 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:
And on Ubuntu 18.04:
loqs commentedon Aug 9, 2018
@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.
jcheng5 commentedon Aug 9, 2018
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.
znmeb commentedon Aug 9, 2018
Note for Arch Linux users - all of the open "tasks" (their word for bugs) relating to this issue have been closed.
wch commentedon Aug 10, 2018
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?
loqs commentedon Aug 10, 2018
Arch Linux with glibc 2.28 no issues with 3a41561
sanjmeh commentedon Feb 4, 2019
I got the same error without even packages
laterorlearnrThis 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.
msberends commentedon Mar 21, 2019
Same here:
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).
wch commentedon Mar 21, 2019
@msberends this was fixed a while back. What version of later are you trying to install?
msberends commentedon Mar 22, 2019
I’m not, I get this error while installing
shinyand 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?
jcheng5 commentedon Mar 22, 2019
@msberends Can you try
install.packages("later"), then try installing shiny again?jcheng5 commentedon Mar 22, 2019
Oh actually, before you do that, tell us what
packageVersion("later")says, then try installinglater?msberends commentedon Mar 23, 2019
packageVersion("later")returned 0.7.5. I don’t get it, RStudio said all other packages where up to date ?!After this,
later0.8.0 got installed and all worked fine! Thank you so much!! Sorry for bothering you 🙂