Repository navigation
fix: pin zig to stop release memory growth and parse whois offset dates - #180
Merged
Merged
Conversation
cargo-zigbuild pulled zig 0.16, whose bundled libc replaces musl's mallocng with Zig's SmpAllocator. The server allocates query rows on sqlx-sqlite worker threads and frees them on tokio workers; memory freed that way was never reused or returned, so v1.0.0-beta.1 grew linearly (~20 MB/day idle, 755 MB after a month on the demo instance). The same code linked against mallocng stays flat under the same load, and a zig 0.15.2 build keeps mallocng.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the unbounded memory growth of release server builds and a WHOIS monitor that failed on every check.
Release builds leak memory (zig 0.16 allocator)
The demo instance (
v1.0.0-beta.1) grew linearly from 124 MB to 755 MB over a month while idle. Container cgroup stats showed the growth was anonymous heap (anon 740 MB, file cache 31 MB), not page cache.Root cause: the release workflow ran
pip install cargo-zigbuild, which pulled zig 0.16. Zig 0.16's bundled libc replaces musl'smallocngwith Zig'sSmpAllocator. The server allocates query rows on sqlx-sqlite worker threads and frees them on tokio workers, and memory freed that way was never reused or returned to the OS.Evidence, using the same write load (200 fast-failing TCP monitors):
1.0.0-beta.1(zig 0.16)rust:1-alpine(mallocng)Swapping the Rust global allocator to mimalloc only helped partially, because SQLite's C allocations still go through libc
malloc, and it also raised the idle baseline, so this PR pins the toolchain instead.release.yml: pinziglang==0.15.2, which still builds muslmallocng. This covers both server and agent release binaries.scripts/memory-soak.shplustests/manual/server-memory-soak.md: a repeatable soak that fails when RssAnon keeps growing under write load. It fails on a zig 0.16 build and passes on a zig 0.15.2 build.WHOIS expiry dates with numeric UTC offsets
whois-rustfollows the registrar referral, and registrars such as MarkMonitor reportRegistrar Registration Expiration Date: 2028-09-13T07:00:00+0000. The parser only acceptedZ-suffixed or naive timestamps, so thegoogle.commonitor on the demo had failed 7984 checks in a row.parse_date_stringnow also accepts%zoffsets (with or without fractional seconds) and normalizes them to UTC.Verification
cargo zigbuild --release --locked --target x86_64-unknown-linux-muslbuilds the server and agent with zig 0.15.2.scripts/memory-soak.sh: zig 0.16 build FAIL (+7.7 MB in 180s), zig 0.15.2 build PASS.cargo test -p serverbee-server --lib checker::whois: 81 passed, including new failing-first tests for offset formats.google.commonitor succeeds with expiry2028-09-13and registrarMarkMonitor, Inc..cargo clippy -p serverbee-server -- -D warningspasses.Follow-up
Deployments only pick up the allocator fix after a new release image is published and
SERVERBEE_IMAGE_TAGindeploy/railway/Dockerfileis bumped from1.0.0-beta.1.