nx10 / httpgd

Asynchronous http server graphics device for R.
https://nx10.github.io/httpgd
GNU General Public License v2.0
365 stars 19 forks source link

Server immediately crash #150

Closed raffaem closed 3 months ago

raffaem commented 5 months ago

Thank you very much for this package.

It is what I need for my workflow.

I installed from github, since for the time being is not available on CRAN.

I start the server, but after opening the webpage in my browser, the server crashes.

Here is the code I'm running:

➜ radian
Using 18 cores for parallelisation
R version 4.3.2 (2023-10-31) -- "Eye Holes"
Platform: x86_64-pc-linux-gnu (64-bit)
(I) r$> library(httpgd)
(I) r$> hgd()
httpgd server running at:
  http://127.0.0.1:35723/live?token=7fM3mBoI
(I) r$> # Now I click on the link to open in the web browser
(I) r$> /usr/lib/gcc/x86_64-pc-linux-gnu/12.3.0/include/c++/bits/stl_vector.h:1123: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; reference = unsigned int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
Aborted (core dumped)
[ble: exit 134]

Environment

igutermes commented 5 months ago

Just to add some information: if I start httpgd server fro Emacs, it crashes. On the other hand, it works fine if started from VScode.

raffaem commented 5 months ago

Last git still crashing for me:

r$> /usr/lib/gcc/x86_64-pc-linux-gnu/12.3.0/include/c++/bits/stl_vector.h:1123: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; reference = unsigned int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
Aborted (core dumped)
igutermes commented 5 months ago

@raffaem are you using vscode?

raffaem commented 5 months ago

@raffaem are you using vscode?

I'm using radian

nx10 commented 5 months ago

Does it work if you plot something before accessing the url?

raffaem commented 5 months ago

Does it work if you plot something before accessing the url?

Yes, thank you.

nx10 commented 5 months ago

Thanks! I'm not getting this on my machine but will investigate.

nx10 commented 4 months ago

Are you still experiencing this issue? If yes could you provide some more information about the environment that its happening in?

raffaem commented 4 months ago

Yes I am still experiencing the issue.

raffaem commented 4 months ago

I have removed both httpgd and unigd, installed from CRAN, and I'm still experiencing the issue.

raffaem commented 4 months ago

Here is sessionInfo after loading the packages:

r$> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.12.0
LAPACK: /usr/lib/liblapack.so.3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_DK.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

time zone: Europe/Rome
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] httpgd_2.0.1

loaded via a namespace (and not attached):
[1] compiler_4.3.3    tools_4.3.3       parallel_4.3.3    unigd_0.1.0       systemfonts_1.0.6
nx10 commented 4 months ago

Where does the parallelisation part in your original post come from?

➜ radian
Using 18 cores for parallelisation

I do not get that when I start radian.

raffaem commented 4 months ago

From my ~/.Rprofile

nx10 commented 4 months ago

Could you post your ~/.Rprofile (or the part where you set up parallelization)?

raffaem commented 4 months ago
# .Rprofile
# see: https://wiki.archlinux.org/title/R#Profile

# The .First function is called after everything else in .Rprofile is executed
.First <- function() {
  # Print a welcome message
  # message("Welcome back ", Sys.getenv("USER"), "!\n",
  #         version$version.string, "\n",
  #         "getwd()=", getwd(), "\n",
  #         "R_LIBS_USER=", Sys.getenv("R_LIBS_USER"), "\n",
  #         ".libPaths()=", .libPaths())
}

# Se default browser
options(browser = "qutebrowser")
# Number of digits to print. Default is 7, max is 15
options(digits = 12)
# Penalty applied to inhibit the use of scientific notation
options(scipen = 2)
# Do not show stars indicating statistical significance in model outputs
options(show.signif.stars = FALSE)
local({
  # Detect the number of cores available for use in parallelisation
  n <- max(parallel::detectCores() - 2L, 1L)
  message("Using ", n, " cores for parallelisation")
  # Parallel compilation of the source files of a single package
  Sys.setenv(MAKEFLAGS = paste0("-j", n))
  # Sys.setenv(CFLAGS="-march=native")
  # Sys.setenv(CPPFLAGS="-march=native")
  # Parallel compilation of the different packages passed to a install.packages() call
  options(Ncpus = n)
  # Parallel apply-type functions via 'parallel' package
  options(mc.cores = n)
})
# Post-mortem debugging facilities
error <- quote(dump.frames("${R_HOME_USER}/testdump", TRUE))

# Set CRAN Mirror
# see: https://wiki.archlinux.org/title/R#Set_CRAN_mirror_across_R_sessions
local({
  r <- getOption("repos")
  r["CRAN"] <- "https://cloud.r-project.org/"
  options(repos = r)
})

# Install a library if it is missing, then load it
# see: https://stackoverflow.com/a/44660688/1719931
using <- function(...) {
  libs <- unlist(list(...))
  req <- unlist(lapply(libs, require, character.only = TRUE))
  need <- libs[req == FALSE]
  if (length(need) > 0) {
    install.packages(need)
    lapply(need, require, character.only = TRUE)
  }
}

# Disable completion from the language server
# as it is already provided by cmp-r
# see: https://github.com/R-nvim/cmp-r
# options(languageserver.server_capabilities =
#         list(completionProvider = FALSE, completionItemResolve = FALSE))
igutermes commented 3 months ago

Installed from cran and bug persists...

nx10 commented 3 months ago

@igutermes could you please also post your system information? Unfortunately I am still not able to replicate this

igutermes commented 3 months ago

Of course. Sorry for not posting earlier. Here is info about my session

R version 4.3.3 (2024-02-29)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora Linux 39 (Workstation Edition)

Matrix products: default
BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP;  LAPACK version 3.11.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

time zone: America/Fortaleza
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] httpgd_2.0.1

loaded via a namespace (and not attached):
[1] compiler_4.3.3    tools_4.3.3       unigd_0.1.0       systemfonts_1.0.6
[5] CoprManager_0.5.5
> 
raffaem commented 3 months ago

I'm not an expert of R package development. Is there no way to get a significant backtrace?

igutermes commented 3 months ago

I have been testing and found that if you run the serves, cleate a plot, and then open the httpgd url in the browser, it works just fine.

## Leads to crash

httpgd::hgd()

httpgd::hgd_browse()

hist(rnorm(100))

## Works 

httpgd::hgd()

hist(rnorm(100))

httpgd::hgd_browse()
Alex-Romanko commented 3 months ago

Experienced the same issue. If I run httpgd::hgd() and follow the link with no plots created the server crashes with the R session itself. But when I send a plot to the device it works as expected.

raffaem commented 3 months ago

I have no experience in developing R packages in another language, but I mean, there must be a way to obtain a useful backtrace

nx10 commented 3 months ago

@raffaem you can run R with a C/C++ debugger attached, and compile + run httpgd from there. This article shows a few options depending on OS + compiler: https://blog.davisvaughan.com/posts/2019-04-05-debug-r-package-with-cpp/

If you are able to get a full stack trace with this please share! I expect it to be an easy fix with that

raffaem commented 3 months ago
➜  R -d gdb
GNU gdb (GDB) 14.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/lib64/R/bin/exec/R...
Reading symbols from /home/raffaele/.cache/debuginfod_client/16693b3cdce9d7f71de365fce9c4414b6aef17ac/debuginfo...                      
(gdb) library(httpgd)
Undefined command: "library".  Try "help".
(gdb) run
Starting program: /usr/lib/R/bin/exec/R --quiet --no-save
Downloading separate debug info for system-supplied DSO at 0x7ffff7fc6000                                                               
Download failed: Connection reset by peer.  Continuing without separate debug info for system-supplied DSO at 0x7ffff7fc6000.           
[Thread debugging using libthread_db enabled]                                                                                           
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[Detaching after vfork from child process 1850263]                                                                                      
Using 18 cores for parallelisation
[Detaching after vfork from child process 1850270]                                                                                      
[Detaching after vfork from child process 1850272]
> library(httpgd)                                                                                                                       
Downloading separate debug info for /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/systemfonts/libs/systemfonts.so
Download failed: Connection reset by peer.  Continuing without separate debug info for /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/systemfonts/libs/systemfonts.so.
Downloading separate debug info for /usr/lib/libX11.so.6                                                                                
Download failed: Connection reset by peer.  Continuing without separate debug info for /usr/lib/libX11.so.6.                            
> hgd()                                                                                                                                 
[New Thread 0x7ffff1e006c0 (LWP 1852391)]
httpgd server running at:
[New Thread 0x7ffff14006c0 (LWP 1852392)]
[New Thread 0x7ffff0a006c0 (LWP 1852393)]
[New Thread 0x7fffebe006c0 (LWP 1852394)]
[New Thread 0x7fffeb4006c0 (LWP 1852395)]
[New Thread 0x7fffeaa006c0 (LWP 1852396)]
[New Thread 0x7fffea0006c0 (LWP 1852397)]
[New Thread 0x7fffe96006c0 (LWP 1852398)]
[New Thread 0x7fffe8c006c0 (LWP 1852399)]
[New Thread 0x7fffdfe006c0 (LWP 1852400)]
[New Thread 0x7fffdf4006c0 (LWP 1852401)]
[New Thread 0x7fffdea006c0 (LWP 1852402)]
[New Thread 0x7fffde0006c0 (LWP 1852403)]
[New Thread 0x7fffdd6006c0 (LWP 1852405)]
[New Thread 0x7fffdcc006c0 (LWP 1852406)]
[New Thread 0x7fffd3e006c0 (LWP 1852408)]
[New Thread 0x7fffd34006c0 (LWP 1852409)]
[New Thread 0x7fffd2a006c0 (LWP 1852410)]
[New Thread 0x7fffd20006c0 (LWP 1852411)]
[New Thread 0x7fffd16006c0 (LWP 1852412)]
[New Thread 0x7fffd0c006c0 (LWP 1852418)]
  http://127.0.0.1:34895/live?token=1ecGVoAB
> /usr/include/c++/13.2.1/bits/stl_vector.h:1125: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; reference = unsigned int&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

Thread 6 "R" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffeb4006c0 (LWP 1852395)]
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44       return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;                                                 
(gdb) backtrace
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007ffff78ab393 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007ffff785a6c8 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007ffff78424b8 in __GI_abort () at abort.c:79
#4  0x00007ffff4add3b2 in std::__glibcxx_assert_fail (file=file@entry=0x7ffff3d54fa0 "/usr/include/c++/13.2.1/bits/stl_vector.h", 
    line=line@entry=1125, 
    function=function@entry=0x7ffff3d553d8 "std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; reference = unsigned int&; size_type = long unsigne"..., 
    condition=condition@entry=0x7ffff3d54000 "__n < this->size()") at /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/debug.cc:61
#5  0x00007ffff3d464fc in std::vector<unsigned int, std::allocator<unsigned int> >::operator[] (this=<optimized out>, 
    __n=<optimized out>) at /usr/include/c++/13.2.1/bits/stl_vector.h:1125
#6  std::vector<unsigned int, std::allocator<unsigned int> >::operator[] (__n=<optimized out>, this=<optimized out>, 
    this=<optimized out>, __n=<optimized out>) at /usr/include/c++/13.2.1/bits/stl_vector.h:1123
#7  unigd::ex::find_results::c_repr (this=this@entry=0x7fffd4012530)
    at /tmp/RtmpYneZe0/R.INSTALL6a0d9df20aab/unigd/src/unigd_external.cpp:16
#8  0x00007ffff3d49ae7 in unigd::ex::api_plots_find (ugd_handle=0x555557f42ed0, offset=0, limit=0, results=0x7fffeb3fe7b0)
    at /tmp/RtmpYneZe0/R.INSTALL6a0d9df20aab/unigd/src/unigd_external.cpp:127
#9  0x00007ffff2bd64e6 in operator() (req=..., __closure=0x7fffec000ed0)
    at /home/raffaele/progetti_altrui/httpgd/src/httpgd_webserver.cpp:293
#10 crow::detail::wrapped_handler_call<httpgd::web::WebServer::run()::<lambda(const crow::request&)> >(crow::request &, crow::response &, const struct {...} &) (req=..., res=..., f=...) at lib/crow/middleware.h:233
#11 0x00007ffff2bf77e3 in std::function<void (crow::request const&, crow::response&)>::operator()(crow::request const&, crow::response&) const (__args#1=..., __args#0=..., this=0x7fffec000ed0) at /usr/include/c++/13.2.1/bits/std_function.h:591
#12 crow::detail::routing_handler_call_helper::call<crow::detail::routing_handler_call_helper::call_params<std::function<void (crow::request&, crow::response&)> >, 0, 0, 0, 0, crow::black_magic::S<>, crow::black_magic::S<> >::operator()(crow::detail::routing_handler_call_helper::call_params<std::function<void (crow::request&, crow::response&)> >) (cparams=..., this=<optimized out>)
    at lib/crow/routing.h:225
#13 crow::TaggedRule<>::handle(crow::request&, crow::response&, crow::routing_params const&) (this=0x7fffec000e40, req=..., res=..., 
    params=...) at lib/crow/routing.h:693
#14 0x00007ffff2bf17a1 in crow::Router::handle_rule<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard> > (
    this=<optimized out>, rp=..., res=..., req=..., rule=<optimized out>) at lib/crow/routing.h:1732
#15 crow::Router::handle<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard> > (found=..., res=..., req=..., 
    this=<optimized out>) at lib/crow/routing.h:1681
#16 crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::handle (found=..., res=..., req=..., this=<optimized out>)
    at lib/crow/app.h:88
#17 crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::--Type <RET> for more, q to quit, c to continue without paging--
web::WebServer::TokenGuard>::handle (this=0x7fff740038b0) at lib/crow/http_connection.h:186
#18 0x00007ffff2be2d4b in crow::HTTPParser<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard> >::process_message (this=<optimized out>) at lib/crow/parser.h:162
#19 crow::HTTPParser<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard> >::on_message_complete (self_=<optimized out>) at lib/crow/parser.h:99
#20 0x00007ffff2c01bd9 in crow::http_parser_execute(crow::http_parser*, crow::http_parser_settings const*, char const*, unsigned long) [clone .constprop.0] (parser=parser@entry=0x7fff74004920, 
    data=data@entry=0x7fff74003920 "GET /plots HTTP/1.1\r\nHost: 127.0.0.1:34895\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0\r\nAccept: */*\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, def"..., len=len@entry=389, 
    settings=<optimized out>) at lib/crow/http_parser_merged.h:1709
#21 0x00007ffff2c0e25e in crow::HTTPParser<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard> >::feed (length=389, 
    buffer=0x7fff74003920 "GET /plots HTTP/1.1\r\nHost: 127.0.0.1:34895\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0\r\nAccept: */*\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, def"..., this=<optimized out>)
    at lib/crow/parser.h:126
#22 crow::HTTPParser<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard> >::feed (length=389, 
    buffer=0x7fff74003920 "GET /plots HTTP/1.1\r\nHost: 127.0.0.1:34895\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0\r\nAccept: */*\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, def"..., this=<optimized out>)
    at lib/crow/parser.h:110
#23 crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}::operator()(std::error_code const&, unsigned long) const [clone .isra.0] (__closure=0x7fffeb3ff660, bytes_transferred=389, ec=...) at lib/crow/http_connection.h:475
#24 0x00007ffff2bed261 in asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, std::error_code, unsigned long>::operator()() (this=0x7fffeb3ff660)
    at /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/AsioHeaders/include/asio/detail/bind_handler.hpp:286
#25 asio::asio_handler_invoke<asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, std::error_code, unsigned long> >(asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, std::error_code, unsigned long>&, ...) (function=...)
    at /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/AsioHeaders/include/asio/handler_invoke_hook.hpp:87
#26 asio_handler_invoke_helpers::invoke<asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, std::error_code, unsigned long>, crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer--Type <RET> for more, q to quit, c to continue without paging--
::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}>(asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, std::error_code, unsigned long>&, crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}&) (context=..., function=...)
    at /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/AsioHeaders/include/asio/detail/handler_invoke_helpers.hpp:54
#27 asio::detail::handler_work<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, asio::any_io_executor, void>::complete<asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, std::error_code, unsigned long> >(asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, std::error_code, unsigned long>&, crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}&) (
    this=<optimized out>, handler=..., function=...)
    at /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/AsioHeaders/include/asio/detail/handler_work.hpp:511
#28 asio::detail::handler_work<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, asio::any_io_executor, void>::complete<asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, std::error_code, unsigned long> >(asio::detail::binder2<crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, std::error_code, unsigned long>&, crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}&) (
    handler=..., function=..., this=0x7fffeb3ff690)
    at /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/AsioHeaders/include/asio/detail/handler_work.hpp:504
#29 asio::detail::reactive_socket_recv_op<asio::mutable_buffers_1, crow::Connection<crow::SocketAdaptor, crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::do_read()::{lambda(std::error_code const&, unsigned long)#1}, asio::any_io_executor>::do_complete(void*, asio::detail::scheduler_operation*, std::error_code const&, unsigned long)
    (owner=0x7fffec003310, base=0x7fffd4010490)
    at /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/AsioHeaders/include/asio/detail/reactive_socket_recv_op.hpp:144
#30 0x00007ffff2c00031 in asio::detail::scheduler_operation::complete (bytes_transferred=1, ec=std::error_code = { }, 
    owner=0x7fffec003310, this=0x7fff74002270)
    at /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/AsioHeaders/include/asio/detail/scheduler_operation.hpp:39
#31 asio::detail::scheduler::do_run_one (ec=..., this_thread=..., lock=<synthetic pointer>..., this=0x7fffec003310)
    at /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/AsioHeaders/include/asio/detail/impl/scheduler.ipp:491
--Type <RET> for more, q to quit, c to continue without paging--
#32 asio::detail::scheduler::run(std::error_code&) [clone .constprop.0] (this=0x7fffec003310, ec=std::error_code = { })
    at /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/AsioHeaders/include/asio/detail/impl/scheduler.ipp:209
#33 0x00007ffff2bdf95d in crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}::operator()() const ()
    at /home/raffaele/R/x86_64-pc-linux-gnu-library/4.3/AsioHeaders/include/asio/impl/io_context.ipp:62
#34 0x00007ffff2beb39b in std::__invoke_impl<void, crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}>(std::__invoke_other, crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}&&) (__f=...) at /usr/include/c++/13.2.1/bits/invoke.h:60
#35 std::__invoke<crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}>(crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}&&) (__fn=...)
    at /usr/include/c++/13.2.1/bits/invoke.h:96
#36 std::thread::_Invoker<std::tuple<crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}> >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (
    this=<optimized out>) at /usr/include/c++/13.2.1/bits/std_thread.h:292
#37 std::thread::_Invoker<std::tuple<crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}> >::operator()() (this=<optimized out>)
    at /usr/include/c++/13.2.1/bits/std_thread.h:299
#38 std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}> >, void>::operator()() const (this=0x7fffeb3ffd90)
    at /usr/include/c++/13.2.1/future:1432
#39 std::__invoke_impl<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}> >, void>&>(std::__invoke_other, std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}> >, void>&) (__f=...) at /usr/include/c++/13.2.1/bits/invoke.h:61
#40 std::__invoke_r<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>, std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}> >, void>&>(std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}> >, void>&)--Type <RET> for more, q to quit, c to continue without paging--
 (__fn=...) at /usr/include/c++/13.2.1/bits/invoke.h:139
#41 std::_Function_handler<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> (), std::__future_base::_Task_setter<std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>, std::thread::_Invoker<std::tuple<crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}> >, void> >::_M_invoke(std::_Any_data const&) (__functor=...)
    at /usr/include/c++/13.2.1/bits/std_function.h:291
#42 0x00007ffff2bbb8dd in std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>::operator()() const (this=<optimized out>) at /usr/include/c++/13.2.1/bits/std_function.h:591
#43 std::__future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*) (this=0x7fffec0051a0, __f=<optimized out>, __did_set=0x7fffeb3ffd00)
    at /usr/include/c++/13.2.1/future:589
#44 0x00007ffff78ae6af in __pthread_once_slow (once_control=0x7fffec0051b8, init_routine=0x7ffff4ae0230 <std::__once_proxy()>)
    at pthread_once.c:116
#45 0x00007ffff2becded in __gthread_once (__func=<optimized out>, __once=0x7fffec0051b8)
    at /usr/include/c++/13.2.1/x86_64-pc-linux-gnu/bits/gthr-default.h:700
#46 std::call_once<void (std::__future_base::_State_baseV2::*)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*), std::__future_base::_State_baseV2*, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*>(std::once_flag&, void (std::__future_base::_State_baseV2::*&&)(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*), std::__future_base::_State_baseV2*&&, std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*&&, bool*&&) (
    __f=@0x7fffeb3ffd20: (void (std::__future_base::_State_baseV2::*)(class std::__future_base::_State_baseV2 * const, class std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter>()> *, bool *)) 0x7ffff2bbb8b0 <std::__future_base::_State_baseV2::_M_do_set(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>*, bool*)>, __once=...) at /usr/include/c++/13.2.1/mutex:907
#47 std::__future_base::_State_baseV2::_M_set_result(std::function<std::unique_ptr<std::__future_base::_Result_base, std::__future_base::_Result_base::_Deleter> ()>, bool) (__ignore_failure=false, __res=..., this=0x7fffec0051a0) at /usr/include/c++/13.2.1/future:428
#48 std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<crow::Server<crow::Crow<crow::CORSHandler, httpgd::web::WebServer::TokenGuard>, crow::SocketAdaptor, crow::CORSHandler, httpgd::web::WebServer::TokenGuard>::run()::{lambda()#1}> >, void>::_M_run()
    (this=0x7fffec0051a0) at /usr/include/c++/13.2.1/future:1774
#49 0x00007ffff4ae1943 in std::execute_native_thread_routine (__p=0x7fffec004f30)
    at /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/thread.cc:104
#50 0x00007ffff78a955a in start_thread (arg=<optimized out>) at pthread_create.c:447
#51 0x00007ffff7926a3c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
nx10 commented 3 months ago

Thank you very much! I have committed a potential fix to the unigd repo. Could you try installing the latest dev version from there and test if it fixed the issue?

remotes::install_github("nx10/unigd")
raffaem commented 3 months ago

Thank you very much! I have committed a potential fix to the unigd repo. Could you try installing the latest dev version from there and test if it fixed the issue?

remotes::install_github("nx10/unigd")

Looks like it does.

Why you did not experience it?

nx10 commented 3 months ago

In principle it was a stupid mistake. At some point in the code I obtained a pointer to the first element in a vector - which is apparently undefined behaviour for empty vectors in C++. Meaning it does something different depending on what C++ compiler / standard library is used. With all my test setups it seems to just return a null pointer as I expected it would, with your setup it seems to panic.

I removed all instances in unigd where I did something similar with a different, safe way to do this.

nx10 commented 3 months ago

Thanks again for your help tracking this down! I will try to make a new release on CRAN soon.