Segfault when libuv symbols (e.g. from libjulia) are loaded before httpuv: bundled libuv calls get interposed
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- C
- 星标
- 252
- 派生
- 87
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rstudio/httpuv 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
-
难度 5/5 一周以上 新手友好度 30/100
-
难度 4/5 3-5 天 新手友好度 45/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
feature good first issue :heart: help wanted :heart: upkeep
难度 3/5 1-2 天 新手友好度 25/100
相似的 Issue
-
Status: Opened
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
FriendsofECCE/ECCE#1018 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
immortalwrt/immortalwrt#2522 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
severity: low
难度 2/5 1-3 小时 新手友好度 64/100
luainkernel/lunatik#2530 ·
维护者通常 1 天内回复