Skip to content

Zero 0.5.4 - update tool chain support to 0.17

Latest

Choose a tag to compare

@im-ng im-ng released this 30 Nov 16:12
bc8f0e2

Zero 0.5.4

Zero 0.5.4 is the Zig 0.17.0 release. It requires Zig 0.17.0 or newer.

This is a hard toolchain cut — 0.5.4 does not build on 0.16.x.

These notes cover every change since v0.5.3.

Breaking changes

Read these before you upgrade.

Minimum Zig is now 0.17.0

The toolchain moved to 0.17.0. The codebase relies on language and std.Build
APIs that 0.17 removed or changed (the @Tuple builtin, the @typeInfo field
arrays, addPassthruArgs). 0.16.x is no longer supported on main branch.

# before
zig 0.16.0
# after
zig 0.17.0

Dependency forks changed

build.zig.zon now wires the dependency tree to 0.17-ready sibling forks:

  • httpz (im-ng/http.zig),
  • protobuf (Arwalk/zig-protobuf),
  • opentelemetry(im-ng/opentelemetry-zig),
  • regexp (tiehuis/zig-regex),
  • sqlite(im-ng/zig-sqlite), plus zbench and zdt bumps.

If you pinned any of these directly, repoint to the 0.17 versions.

Example build.zig must port b.args

Every example build.zig (and src/bench/main.zig) replaced the old
b.args passthrough with addPassthruArgs().

Any custom example build script you maintain must do the same or
it will fail to compile under 0.17.

// before
b.args = &.{...};
// after
step.addPassthruArgs(&.{...});

Vault overrides config removed

The vault overrides config path was removed. If you relied on runtime vault
key overrides, move that configuration into the standard config surface before
upgrading.

Outbound timeouts are now enforced

SERVICE_<NAME>_TIMEOUT_MS used to emit a startup warning and do nothing. It
is now a whole-request deadline.

A stalled downstream returns error.RequestTimeout instead of hanging.

Review configured timeouts before upgrading.

API keys are compared strictly

Stored API keys are checked with a constant-time compare, not just by existence
in KV. A metadata-style value in the key store no longer authenticates. Store
real secrets as keys.

Default backend registration fails fast

A failed default SQL or pub/sub registration now stops startup instead of
silently dropping the backend. Repair the config rather than running in a
degraded state.

What's new

Zig 0.17 foundation

Hard cut to the 0.17 toolchain. Source and build scripts were ported to the new
APIs, and addPassthruArgs() replaced b.args throughout. This is the
foundation the rest of 0.5.4 sits on.

Security and correctness

Two audit passes. The first closed request-path leaks and auth bugs; the
second hardened parsing, escaping, and signing.

  • auth: plug session use-after-free in createSession (errdefer); dup
    claims (iss/aud/sub/jti/role) before destroy in retrieveClaims.
  • Basic auth: split on the first colon, reject colon-less credentials, and
    stop reading an undefined password slice.
  • rate limiter: correct Retry-After window math, pass the request arena
    to setRetryAfter, and sweep expired buckets before max_entries.
  • http: safe Basic-auth decode against AUTH_KEYS; dispatch via
    Error.statusForError with a generic JSON body.
  • MySQL: set NO_BACKSLASH_ESCAPES per connection, double embedded quotes,
    restore escaping tests, and add a real-server injection round-trip test.
  • SigV4: propagate allocation failure, remove the length-based free
    heuristic, assert the hex output bound, and add AWS test vectors.
  • GraphQL: reject malformed numeric literals instead of coercing them to
    zero.
  • SQL metrics: emit a real operation label; never use raw SQL as a label.
  • pub/sub: fix arena leak in dispatch runHook (errdefer→defer); SQS
    sigv4 content-sha256 dup, JSON publish/delete, JSON+XML poll.
  • teardown: MQTT started flag + ordered destroy; NATS/SQS/GCP store the
    thread handle and join in deinit; container deinits Sqs/Gcp.
  • context: cleanup() rolls back SQL and frees baggage; MySQL per-request
    session when container.MySQL is set.
  • cronz: 5/6-field schedule parse; reject step==0, inverted ranges, and
    u16 overflow; lock the mutex across the whole job iteration.
  • KV memory: free duped expiry-index keys at teardown.
  • mutexes: replace silent lock catches with lockUncancelable.

Outbound client: deadlines, retries, and partition keys

  • Retry 429/5xx honoring Retry-After (capped at 60s).
  • SERVICE_<NAME>_TIMEOUT_MS races the HTTP call against an Io timer, cancels
    the in-flight task on expiry, and rechecks the clock so a late response
    cannot slip through.
  • A stale idle keep-alive socket is retried once as a connection blip, not
    counted as an upstream failure.
  • Kafka TLS cert verification is on by default
    (KAFKA_TLS_INSECURE_SKIP_VERIFY=false).
  • Redis resilience: rdz.reconnect() heals a dead socket in place; the health
    probe rebuilds it before reporting unavailable.
  • PublishWithKey(subject, payload, key) carries an optional partition key.
    Kafka uses it to keep related messages ordered on one partition; other
    backends ignore it. The legacy Publish still forwards null.
  • The fakeserver can stall a response so deadline tests are real. The delay
    uses an OS-level sleep, so a virtual-clock runner cannot skip it, and the
    deadline test was adjusted for timer scheduling.

Architecture and data path

  • Additive named SQL (addSQL/GetSQL) and pub/sub (addPubSub/GetPubSub).
  • Transactional outbox (addOutbox): dialect-aware table, enqueue, and poller
    (src/outbox.zig).
  • Fail-fast startup: drop std.process.exit on SQL/duckdb load errors.
  • healthProbe snapshots the underlying service changes.
  • AutoCRUD routes through the ctx.SQL interface (circuit breaker + datasource
    metrics) instead of a per-dialect backend switch. The dialect dispatcher now
    picks the right $N/? statement per request on every CRUD verb.
  • Service client reuses a persistent HTTP client per request.
  • Dependencies stay optional so the static-build claim holds.
  • Broader leak cleanup in config, OTel, and vault paths.

SQLite pool and WAL

A single connection behind a mutex serialized every request, so WAL could not
let readers run alongside a writer.

  • Requests borrow a pooled connection per call and queue on a condition
    variable when all are busy. No request fails on pool exhaustion.
  • WAL and busy_timeout (5000 ms) are set on every connection at init.
  • SQLITE_POOL_SIZE sets the pool size (default 4, max 64).
  • The sqlite dependency was updated, and callers now pass target and
    optimize through to it.
  • Integration tests pin the in-memory SQLite pool to one connection: each
    :memory: handle is a separate database.

Observability

  • OpenTelemetry is enabled by configuring an OTLP endpoint, not a feature
    flag. Tracing and metrics are wired from the first request.
  • The metrics cardinality cap is config-driven (METRICS_CARDINALITY_LIMIT,
    default 4096). An explicit 0 now really disables the cap; before this fix,
    0 and "unset" collapsed to the same value.
  • Label hashing hashes field lengths before bytes to avoid boundary
    collisions. A read lock plus a remembered-hash fast path keeps fixed-route
    metric updates lock-free on the request path. Overflows surface as the
    otel_metric_overflow series.

Shutdown and lifecycle

  • The signal handler only sets an atomic flag. All teardown runs on the main
    thread; the AppInstance/hServer globals are gone and shutdown state is
    reset.
  • The health-refresher thread is joined before the container is freed, and the
    last published health snapshot is freed in destroy.
  • Handler: correlation-ID fallback, tracz first in middleware, structured
    error logging, and bounded metric labels on error paths.
  • Context: single teardown path, Postgres session in initCli, real W3C trace
    ID.

Platform, CI, and packaging

  • CI pins Zig 0.17.0 and drops macOS from the release matrix. Separately, the
    test suite now runs on macOS too: fakeserver moved from std.os.linux to
    std.c/std.posix, and zsutil.memory has a macOS free-memory fallback.
  • CI gates added: zig fmt --check, test-validation, and helm template.
    Helm generation is excluded from the normal build and bench CI was fixed.
  • Dockerized quick-start steps and Dockerfile updates.

SBOM for tagged releases

Tagged releases produce a CycloneDX 1.6 SBOM (final-sbom.json).

  • scripts/gen-sbom.sh derives components from build.zig.zon with awk and
    jq only. The old cdxgen + syft + cyclonedx-cli merge step is gone:
    those tools cannot read a Zig project and produced empty BOMs.
  • The script fails when the manifest has no dependencies or the component
    count does not match, so an empty SBOM cannot be published.
  • The release workflow just runs the script and uploads the artifact.

Docs and examples

  • Docs: K8s service discovery, data-parity, config reference, error handling,
    upgrades, support cadence, issue triage, release benchmarks, and a release checklist.
  • New examples: zero-starter (health/metrics/SQL/outbound, Dockerfile, Helm,
    CI), zero-vault-pg (Vault + SQL), zero-gcs, zero-rate-limit, and
    zero-supabase. Circuit-breaker usage is documented in zero-service-client.
  • SQL parity test (LIMIT/OFFSET + upsert) and an OTel migrator fix land in the
    integration suite.

Quality

  • zig build test passes under 0.17.0. Unit, integration, and validation
    suites also pass on macOS.
  • All examples build on 0.17.0.
  • New examples: zero-starter, zero-vault-pg, zero-gcs, zero-rate-limit,
    zero-supabase, plus circuit-breaker guidance in zero-service-client.

Upgrade checklist

  1. Install Zig 0.17.0.
  2. Repoint any directly pinned dependency forks to the 0.17 versions.
  3. Port any custom example build.zig from b.args to addPassthruArgs().
  4. Move vault-override configuration into the standard config surface.
  5. Check SERVICE_<NAME>_TIMEOUT_MS values. Timeouts are now enforced.
  6. Store real secrets as API keys. Existence checks no longer authenticate.
  7. Fix default SQL/pub/sub config. A bad registration now stops startup.
  8. Tune SQLITE_POOL_SIZE if you rely on concurrent SQLite reads and writes.
  9. Re-run zig build test and your example builds.