Skip to content

fix: enable jemalloc only in host binaries - #58

Merged
IGN-Styly merged 2 commits into
mainfrom
fix/jemalloc-host-only
Oct 25, 2026
Merged

IGN-Styly merged 2 commits into
mainfrom
fix/jemalloc-host-only

Conversation

@IGN-Styly

Copy link
Copy Markdown
Member

Why mods crash today

enginelib turns on rust-rocksdb's jemalloc feature, and librocksdb-sys builds tikv-jemalloc-sys with unprefixed_malloc_on_supported_platforms, so jemalloc replaces malloc/free. Mods are cdylibs that link enginelib statically, so every mod carried its own private jemalloc:

  • release mods could fail dlopen with "cannot allocate memory in static TLS block" (jemalloc uses initial-exec TLS), or
  • memory allocated on one heap and freed on the other while crossing run(&mut ServerAPI) (Arc<dyn Task>, Strings, registry entries) corrupts the heap.

Fix

Enable the feature in engine/Cargo.toml (host binaries) instead. The server still runs entirely on jemalloc (it exports malloc/free; checked with nm -D), and a mod built on its own has no allocator of its own: its malloc binds to the host's at load time, so there is one heap per process. Mods must be built as separate projects (the voltaero/mod template / cargo rf), not in a --workspace build with the engine, where the feature would unify back in. Documented in AGENTS.md.

Also carried from the magnesium work (ccc4318, already pinned by voltaero/magnesium):

  • #[derive(Verifiable)] matches verify(&self, &[u8]).
  • Client::connect_timeout bounds the Hello handshake.
  • EventBus::fire no longer records events (auth challenges / admin tokens) in its tracing span.

cargo test --workspace passes.

🤖 Generated with Claude Code

- Move RocksDB's jemalloc feature from enginelib to the engine binaries.
  librocksdb-sys builds jemalloc with unprefixed malloc, so every mod that
  linked enginelib carried a private heap: release mods failed dlopen
  ("cannot allocate memory in static TLS block") or corrupted memory crossing
  run(&mut ServerAPI). enginelib is now allocator-neutral; a mod's malloc
  binds to the one the host exports.
- #[derive(Verifiable)]: match the trait's verify(&self, &[u8]).
- Client::connect_timeout: bound the Hello handshake (connect waited 30 s
  on a dead endpoint).
- EventBus::fire: don't record events in the tracing span; auth events
  carry challenges and admin tokens.
- AGENTS.md: point to voltaero/magnesium (management mod) and document the
  allocator rule for mods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c80e9c7e-a9d6-4e27-8c9f-62a6f14756c2
Commits

Reviewing files that changed from the base of the PR and between 25716a1 and 7228a7f.

Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 8
  • AGENTS.md
  • engine/Cargo.toml
  • enginelib/Cargo.toml
  • enginelib/macros/src/lib.rs
  • enginelib/src/event.rs
  • enginelib/src/transport/client.rs
  • enginelib/tests/macros.rs
  • enginelib/tests/transport.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; both previous findings are addressed and no new actionable issues were found.

Summary

Moves RocksDB's jemalloc feature from enginelib to the host binaries and documents how to build mods separately.

  • The engine host owns jemalloc while separately built mods stay allocator-neutral.
  • Clients can choose how long the handshake waits.
  • Derived verifiers check payloads from a borrowed byte slice.
  • Event spans leave event contents out of tracing.
  • Repository housekeeping leaves engine behavior unchanged.

Both previous test-coverage findings are addressed. No new actionable issues were found in the changes since the previous review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Host["engine host binaries"] -->|"enables jemalloc"| RocksDB["rust-rocksdb"]
  Host --> Library["enginelib"]
  Mod["Separately built mod"] --> Library
  Library -->|"does not enable jemalloc"| RocksDB
Loading

Reviews (2) · Last reviewed commit: "test: cover #[derive(Verifiable)] and Cl..." · Reviewed by Greptile

Comment thread enginelib/macros/src/lib.rs Resolved
Comment thread enginelib/src/transport/client.rs Resolved
Addresses review: the derive was never compiled by the tests (they
implement Verifiable by hand), and connect_timeout had no test of its
handshake deadline or of keeping the timeout afterwards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IGN-Styly
IGN-Styly merged commit c752429 into main Oct 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant