Segfault when libuv symbols (e.g. from libjulia) are loaded before httpuv: bundled libuv calls get interposed
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 46/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C
- Star
- 252
- Fork
- 87
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rstudio/httpuv
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Use `{cli}` for errorsĐang mởfeature good first issue :heart: help wanted :heart: upkeep
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
Tất cả issue của rstudio/httpuv
Issue tương tự
-
Status: Opened
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
FriendsofECCE/ECCE#1018 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
immortalwrt/immortalwrt#2522 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
severity: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
luainkernel/lunatik#2530 ·
Maintainer thường phản hồi trong vòng 1 ngày