Segfault when libuv symbols (e.g. from libjulia) are loaded before httpuv: bundled libuv calls get interposed
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 46/100
Línea de trabajo
Start by reading src/Makevars and the libuv selection and linking logic described in the issue; compare a bundled libuv build with a system libuv build. Reproduce the reported segfault using the R reprex with Julia loaded first, then check symbol bindings with LD_DEBUG=bindings. Done means bundled libuv calls stay bound to httpuv when Julia is loaded first and the reprex survives; system libuv builds may still be affected.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
On Linux, if a shared library that exports its own uv_* symbols is loaded into the R process globally before httpuv, httpuv's calls into its bundled libuv resolve to that other libuv. The struct layouts differ, so the server segfaults on the first request.
I hit this with Julia embedded in R (JuliaCall, or packages that load a juliac-compiled library). Julia's loader libjulia.so opens libjulia-internal.so with RTLD_GLOBAL, and that library exports Julia's forked libuv. Just dyn.load()ing libjulia.so is enough to trigger it.
Whether you're affected depends on how httpuv was linked. The crash happens with the Posit Package Manager binary (__linux__/noble). It doesn't happen when I build httpuv from source with Ubuntu's r-base and the bundled libuv (USE_BUNDLED_LIBUV=true), because that R's Makeconf links every package with -Wl,-Bsymbolic-functions (Ubuntu default).
Reprex
Needs julia and curl on the PATH.
libjulia <- system2(
"julia",
c("--startup-file=no", "-e", shQuote('print(joinpath(Sys.BINDIR, Base.LIBDIR, "libjulia.so"))')),
stdout = TRUE
)
dyn.load(libjulia)
port <- httpuv::randomPort()
s <- httpuv::startServer(
"127.0.0.1", port,
list(call = function(req) list(status = 200L, body = "ok"))
)
system2("curl", c("-s", "-o", "/dev/null", paste0("http://127.0.0.1:", port)), wait = FALSE)
for (i in 1:20) httpuv::service(100)
cat("survived\n")
Output with the PPM binary:
*** caught segfault ***
address 0x60, cause 'memory not mapped'
Traceback:
1: execCallbacks(timeoutSecs, all, loop$id)
2: run_now(timeoutMs/1000, all = FALSE)
3: httpuv::service(100)
An irrecoverable exception occurred. R is aborting now ...
Without the dyn.load(), or with loadNamespace("httpuv") before it, the script prints survived.
Diagnosis
LD_DEBUG=bindings shows that when libjulia is loaded first, all 92 of httpuv.so's uv_* references bind to libjulia-internal.so.1.13. In the reverse order they bind to httpuv.so itself.
httpuv.so exports its bundled libuv's symbols (252 uv_*), and in the PPM binary its own calls to them go through the PLT, so they can be interposed. R loads package DLLs with RTLD_LOCAL, but that doesn't help here: the dynamic linker searches the global scope before the library's own symbols, so any libuv already loaded globally wins.
Possible fix
Keep httpuv's references to its bundled libuv internal to httpuv.so, independent of how R was configured. For example, add -Wl,-Bsymbolic-functions to PKG_LIBS in src/Makevars, or build libuv with -fvisibility=hidden.
I tested this by building 1.6.17 from source with USE_BUNDLED_LIBUV=true (bundled libuv, linked with -Bsymbolic-functions). The reprex then survives every time, and LD_DEBUG shows no uv_* references from httpuv.so resolving to libjulia.
(This only helps when httpuv uses its bundled libuv; a build against the system libuv.so.1, which configure picks when libuv1-dev is installed, crashes the same way and no link flag on httpuv's side can prevent that.)
Versions
httpuv 1.6.17 (PPM binary), R 4.6.1, Julia 1.13.2, Linux Mint 22.3 x86_64 (kernel 7.0.0-38-generic).
I ran into this myself; Claude Code (Opus 5.5) helped with debugging and the possible fix.
- Lenguaje dominante
- C
- Estrellas
- 252
- Forks
- 87
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rstudio/httpuv
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Use `{cli}` for errorsAbiertofeature good first issue :heart: help wanted :heart: upkeep
Dificultad 3/5 1-2 días Aptitud para principiantes 25/100
Todos los issues de rstudio/httpuv
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
severity: low
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
luainkernel/lunatik#2530 ·
Los mantenedores suelen responder en 1 día
-
polygonToCells CLI silently drops vertices when whitespace precedes a coordinate's closing bracketAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
issue: bug report
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 2 días