RipGrep musl binaries occasionally segfault during very-large searches
RipGrep musl binaries occasionally segfault during very-large searches
RipGrep 的 musl 二进制文件在进行超大规模搜索时偶尔会发生段错误 (segfault)
Description:
Ripgrep built for x86_64-unknown-linux-musl occasionally crashes with a SIGSEGV when searching very-large trees at a high degree of concurrency. The crashing line is an integrity assertion regarding heap metadata inside MUSL’s mallocng, in a calloc call made from opendir.
描述:
为 x86_64-unknown-linux-musl 构建的 Ripgrep 在高并发环境下搜索超大规模目录树时,偶尔会因 SIGSEGV(段错误)而崩溃。崩溃点位于 MUSL 的 mallocng 内部堆元数据的完整性断言中,该断言是在 opendir 调用的 calloc 函数中触发的。
What are the steps to reproduce the behavior?
Having a sufficiently large search tree seems to be essential for reproduction. Run the attached generate_repro_tree.py. This is an LLM-written program which produces a tree full of random files which mimic the statistics of the repo in which I originally encountered the bug. It will produce a tree containing roughly 20GiB of data across 1.8M files. Then from the root of that tree, run rg in a loop, searching for some arbitrary literal string that isn’t present in the tree: while true; do rg tnoheueunotshisnthukoethnsueothnsiuothonesuioseuinth; done. On my 24-core system, having enough free RAM for the search tree to fit in the kernel’s block cache, it typically takes about a minute for the SIGSEGV to appear.
如何复现该问题?
拥有一个足够大的搜索目录树似乎是复现问题的关键。运行附带的 generate_repro_tree.py 脚本。这是一个由大模型编写的程序,它会生成一个充满随机文件的目录树,模拟了我最初遇到该 Bug 时所在仓库的统计数据。它将生成一个包含约 20GiB 数据、跨越 180 万个文件的目录树。然后,在该目录树的根目录下,循环运行 rg,搜索一个目录树中不存在的任意字符串:while true; do rg tnoheueunotshisnthukoethnsueothnsiuothonesuioseuinth; done。在我的 24 核系统上,当有足够的空闲内存让搜索树放入内核块缓存时,通常只需一分钟左右就会出现 SIGSEGV。
What is the actual behavior?
I get a coredump with the following backtrace:
(Backtrace omitted for brevity, showing the crash occurring within mallocng during opendir operations).
实际表现:
我得到了一个核心转储(coredump),其回溯信息如下:
(为简洁起见省略了回溯信息,显示崩溃发生在 opendir 操作期间的 mallocng 内部)。