Skip to content

fix: pin zig to stop release memory growth and parse whois offset dates - #180

Merged
ZingerLittleBee merged 4 commits into
mainfrom
fix/release-allocator-and-whois-offset
Sep 24, 2026
Merged

ZingerLittleBee merged 4 commits into
mainfrom
fix/release-allocator-and-whois-offset

Conversation

@ZingerLittleBee

Copy link
Copy Markdown
Owner

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's mallocng with Zig's SmpAllocator. 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):

Build RssAnon
Production image 1.0.0-beta.1 (zig 0.16) +12 MB in 5 min, linear
HEAD, zigbuild with zig 0.16 ~2 MB/min, linear
HEAD, alpine rust:1-alpine (mallocng) flat (+0.5 MB)
HEAD, zigbuild with zig 0.15.2 flat (-116 KB after 5000 checks), ~14 MB idle

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: pin ziglang==0.15.2, which still builds musl mallocng. This covers both server and agent release binaries.
  • scripts/memory-soak.sh plus tests/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-rust follows the registrar referral, and registrars such as MarkMonitor report Registrar Registration Expiration Date: 2028-09-13T07:00:00+0000. The parser only accepted Z-suffixed or naive timestamps, so the google.com monitor on the demo had failed 7984 checks in a row. parse_date_string now also accepts %z offsets (with or without fractional seconds) and normalizes them to UTC.

Verification

  • cargo zigbuild --release --locked --target x86_64-unknown-linux-musl builds 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.
  • Live check against the real WHOIS servers: the google.com monitor succeeds with expiry 2028-09-13 and registrar MarkMonitor, Inc..
  • cargo clippy -p serverbee-server -- -D warnings passes.

Follow-up

Deployments only pick up the allocator fix after a new release image is published and SERVERBEE_IMAGE_TAG in deploy/railway/Dockerfile is bumped from 1.0.0-beta.1.

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.
@ZingerLittleBee
ZingerLittleBee merged commit 7122360 into main Sep 24, 2026
11 checks passed
@ZingerLittleBee
ZingerLittleBee deleted the fix/release-allocator-and-whois-offset branch September 24, 2026 17:12
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