AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(server): raise RLIMIT_NOFILE with a concrete rlim_max so macOS accepts it
xerj-org7e050d0a1cba
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e62c8d702..497f41eb0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -28,11 +28,14 @@ symbols instead of plain text.- **Autoindex `Too many open files` (os error 24) crash** on large repos. Eachindex holds segment mmaps, a WAL and a merge task, so discovering a repo that- infers dozens of datasets (django ≈ 74 indices) exhausted file descriptors on- a default macOS soft limit (256), failing at the second index. The server now- raises `RLIMIT_NOFILE` to the hard limit at startup (stepping down for the- macOS kernel cap; best-effort). Reproduced and fixed against real django and- redis clones.+ infers hundreds of datasets (WooCommerce ≈ 413 indices, ~16 descriptors each)+ exhausted file descriptors on a default macOS soft limit (256), failing near+ the start. At startup the server now raises `RLIMIT_NOFILE` toward the hard+ limit using a **concrete** `rlim_max`: macOS rejects `setrlimit(RLIMIT_NOFILE)`+ when `rlim_max` is `RLIM_INFINITY` (its launchd default), so passing that back+ was a silent no-op and the limit stayed at 256 — the raise now sets a concrete+ ceiling and steps down for the `kern.maxfilesperproc` cap (best-effort).+ Reproduced and fixed against real django, redis and WooCommerce clones.- **jemalloc `background_thread currently supports pthread only`** printed onevery macOS launch — the `background_thread` option is now Linux-only, whereit is supported; the decay policy is unchanged.diff --git a/engine/crates/xerj-server/src/main.rs b/engine/crates/xerj-server/src/main.rsindex e624d559c..26101e73a 100644--- a/engine/crates/xerj-server/src/main.rs+++ b/engine/crates/xerj-server/src/main.rs@@ -1293,34 +1293,82 @@ fn raise_nofile_limit() {if libc::getrlimit(libc::RLIMIT_NOFILE, &mut lim) != 0 {return;}- let cur = lim.rlim_cur;- // An "infinity" hard limit (macOS launchd) must be capped to a concrete- // value or setrlimit fails outright; 1,048,576 is generous headroom.- let hard = if lim.rlim_max == libc::RLIM_INFINITY {- 1_048_576- } else {- lim.rlim_max- };- if hard <= cur {- return; // already at the ceiling- }- let mut want = hard;- loop {+ for (cur, max) in nofile_plan(lim.rlim_cur, lim.rlim_max) {let next = libc::rlimit {- rlim_cur: want,- rlim_max: lim.rlim_max,+ rlim_cur: cur,+ rlim_max: max,};if libc::setrlimit(libc::RLIMIT_NOFILE, &next) == 0 {return; // raised}- if want <= cur.saturating_add(1) {- return; // can't beat the inherited soft limit; leave it be- }- want = (want / 2).max(cur + 1);}}}+/// The ordered `(rlim_cur, rlim_max)` pairs to try for RLIMIT_NOFILE, highest+/// first. Pure, so the macOS-only `RLIM_INFINITY` path is unit-testable without+/// a Mac. Every pair uses `rlim_max == rlim_cur` — a CONCRETE value: macOS+/// REJECTS `setrlimit(RLIMIT_NOFILE)` when `rlim_max` is `RLIM_INFINITY` (its+/// launchd default), so the earlier "pass the inherited hard limit back"+/// version was a silent no-op there and the limit stayed at 256. Steps down by+/// halving for the macOS `kern.maxfilesperproc` ceiling until one is accepted.+#[cfg(unix)]+fn nofile_plan(cur: libc::rlim_t, max: libc::rlim_t) -> Vec<(libc::rlim_t, libc::rlim_t)> {+ // Cap an "infinite" hard limit to concrete headroom (1,048,576).+ let hard = if max == libc::RLIM_INFINITY {+ 1_048_576+ } else {+ max+ };+ if hard <= cur {+ return Vec::new(); // already at the ceiling+ }+ let mut plan = Vec::new();+ let mut want = hard;+ loop {+ plan.push((want, want));+ if want <= cur.saturating_add(1) {+ break;+ }+ want = (want / 2).max(cur + 1);+ }+ plan+}++#[cfg(all(test, unix))]+mod nofile_tests {+ use super::nofile_plan;++ #[test]+ fn infinity_hard_yields_only_concrete_maxes() {+ // The macOS case the earlier version silently failed on.+ let plan = nofile_plan(256, libc::RLIM_INFINITY);+ assert!(!plan.is_empty());+ assert_eq!(plan[0], (1_048_576, 1_048_576)); // highest first, concrete+ assert!(plan+ .iter()+ .all(|&(c, m)| c == m && m != libc::RLIM_INFINITY));+ for w in plan.windows(2) {+ assert!(w[0].0 > w[1].0, "must step strictly down");+ }+ assert!(+ plan.last().unwrap().0 <= 257,+ "ends just above the soft limit"+ );+ }++ #[test]+ fn concrete_hard_is_targeted_directly() {+ assert_eq!(nofile_plan(256, 524_288)[0], (524_288, 524_288));+ }++ #[test]+ fn already_at_ceiling_is_noop() {+ assert!(nofile_plan(524_288, 524_288).is_empty());+ assert!(nofile_plan(1024, 512).is_empty());+ }+}+fn main() -> Result<()> {#[cfg(unix)]raise_nofile_limit();