v0.3.0-beta · Release deep dive — published 2026-11-08Fairyfly
v0.3.0-beta is out. Where v0.2.0-beta rounded out the core primitive set (UDP, child_process, HTTP proxies, and direct package sources), v0.3.0-beta is about production readiness, security boundaries, and serverless density.
Across 29 commits, the codebase grew from ~24k lines across 54 Zig files to ~32k lines across 73 Zig files — still small enough to read end-to-end, while closing the gaps that matter when you put a single-binary runtime in front of real traffic.
This post walks through what is new in v0.3.0-beta and why each piece is designed the way it is. You can also read the release notes on GitHub.
At a glance: what changed in v0.3.0-beta
1. Deny-by-default permissions (--allow-*)
What’s new
Every native capability in Fairyfly is now deny-by-default. A script that only runs pure JavaScript (ff hello.js) needs no flags. Touching the filesystem, network, environment variables, subprocesses, or FFI requires an explicit CLI grant:
When code attempts an operation outside its scope, Fairyfly throws a
PermissionDenied error (e.name === "PermissionDenied", e.code === "PERMISSION_DENIED") synchronously before any I/O, socket, or thread job is created:
Why we designed it this way
- CLI-only, never in
ff.jsonor environment variables: If a project manifest or environment variable could grant permissions, a compromised dependency or environment injection could silently escalate its own privileges. Making the command line the single source of truth means the operator launchingffalways sees the exact authority of the process inpsor the container entrypoint. - Immutable at startup: Scopes are parsed once before the QuickJS runtime is initialized. Path scopes are canonicalized against the launch working directory, so a later
process.chdir()cannot move the allowed roots. Workers inherit the exact same policy. - Program loading is a deliberate carve-out:
import,new Worker("./worker.js"),ff startreadingff.json, andff testloadingtest/*.test.jsdo not require--allow-read. Permissions govern what the code can do at runtime, not whether the entrypoint can boot. - Honest threat model: We document permissions as an in-process policy layer, not an OS sandbox.
--allow-runand--allow-ffiexecute native code with the full authority of the OS process, so granting them is trust-equivalent to--allow-all.
2. Cutting Linux serverless RSS by 4× (40 MB → 10.1 MB)
What’s new
While benchmarking Fairyfly on Linux serverless workloads with our static-musl build, we found and eliminated a hidden per-thread memory multiplier:Why it happened and how we fixed it
src/worker/message_port.zig previously declared a 4 MiB threadlocal receive scratch buffer for structured-clone worker messages. Because it was threadlocal, the compiler emitted a 4.25 MiB PT_TLS block into the binary — which the C runtime allocated for every OS thread in the process, including the 16 fetch worker threads and std.Io threads that never touch a MessagePort.
In v0.3.0-beta:
- Lazy
MessagePortscratch allocation: The receive scratch buffer is now allocated lazily on first message use, grown up to the high-water frame size (capped atMAX_FRAME= 4 MiB), reused without reallocating on subsequent frames, and freed when the worker thread exits. Threads that never receive a worker message pay 0 bytes. - Explicit network thread stack sizing: Instead of inheriting Zig’s 16 MiB default thread stack size on
std.Ioworker threads, the pool is bounded to 32 workers with explicit 1 MiB stacks (and 1 MiB stacks on the 16fetchworkers).
3. HTTP server: request headers, reusePort, and 1 MB body spill
What’s new
Request headers in http.serve
The http.serve handler now receives a fourth argument — headers, a web-standard Headers instance populated for both HTTP/1.1 and HTTP/2:
headers.get(name)is case-insensitive and joins duplicate headers with", "(Cookiejoins with"; "per RFC 9113 §8.2.3;Set-Cookiereturns the first value whileheaders.getAll("set-cookie")returns all).- Zero-allocation warm path:
HeadersDataobjects are pooled and retain capacity across requests (with hit/miss counters exposed inprocess.stats().http), so parsing request headers allocates nothing after warm-up. - Header size bounds: Capped at 4 KB for HTTP/1.1 and 64 KiB for HTTP/2. Requests exceeding the cap receive
431 Request Header Fields Too Largeinstead of dropping the session. reusePortoption: Passing{ reusePort: true }enablesSO_REUSEPORTso multipleffprocesses can bind the same port with kernel load balancing.
1 MB HTTP/1.1 request body spill & HTTP/2 bounds
Previously, HTTP/1.1 request headers and bodies shared the per-slot 4 KB static read buffer (413 above ~4 KB). In v0.3.0-beta:
Why this two-tier design
A 4 KB buffer is ideal for 95% of API traffic (GET requests, small JSON POSTs) because it stays inside the preallocated 512-slot connection table with zero heap activity. But webhook payloads, batch inserts, and form submissions routinely exceed 4 KB. By keeping requests ≤ 4 KB in the static slot buffer and spilling larger payloads to the heap up to 1 MB (retaining up to 64 KB per slot and enforcing a hard 64 MB process-wide ceiling), Fairyfly handles real-world request bodies while still guaranteeing a strict upper bound on memory under a slow-POST flood. Spill telemetry is exposed directly viaprocess.stats().http.reqSpill.
Full reference: HTTP Server guide · http API.
4. Graceful shutdown and POSIX signal handling
What’s new
http.serve now returns { port, close }, supports ephemeral OS port assignment via port: 0, accepts an AbortSignal, and drains in-flight requests cleanly:
process now supports POSIX signals (SIGINT, SIGTERM, SIGHUP, SIGUSR1, SIGUSR2):
process.on(sig, fn),process.once(sig, fn),process.off(sig, fn)(up to 8 listeners per signal, dispatched safely on the event-loop thread).process.kill(pid, sig?)(self-signalingprocess.pidis ungated; signaling external PIDs requires--allow-run=kill).
server.close() is called (or when SIGINT/SIGTERM arrives and no custom signal listener is registered):
- The listening socket closes immediately so new connections are refused.
- Idle HTTP/1.1 keep-alive sockets and active WebSockets close.
- In-flight HTTP/1.1 responses are marked
Connection: closeand allowed to finish flushing. - Active HTTP/2 sessions send a
GOAWAYframe and close once in-flight streams complete. server.close()resolves itsPromiseonce all 512 connection slots are free, allowing the event loop to exit naturally with code0.
Why it matters
In container and serverless environments, the orchestrator sendsSIGTERM before stopping an instance. Exiting immediately mid-request causes upstream 502 errors. Built-in connection draining makes zero-downtime deploys and scale-to-zero clean by default.
Full reference: process API · http API.
5. Off-loop native crypto.bcrypt and Web Crypto HMAC
What’s new
crypto.bcrypt.hash and crypto.bcrypt.verify
Fairyfly now includes native, promise-based bcrypt password hashing backed by Zig’s std.crypto.pwhash.bcrypt on a dedicated background worker pool:
- Dedicated bounded pool: 2–4 worker threads (256 KiB stacks) with a fixed 16-slot ring queue and preallocated buffers — zero heap allocation per hash after initialization.
- Event loop stays responsive: At cost 12 (~250 ms) or 4× concurrent cost 11 (134 ms total), timer jitter on the main event loop stays under ~8 ms.
- Fail-fast safety: Passwords > 72 bytes reject immediately (
Error: bcrypt: password exceeds 72 bytes); a 17th concurrent request when the ring queue is full rejects immediately (Error: crypto.bcrypt: queue full). NohashSync/verifySyncexists.
crypto.subtle HMAC (importKey, sign, verify, exportKey)
crypto.subtle now supports HMAC with SHA-1, SHA-256, SHA-384, and SHA-512, including constant-time signature verification:
Why we built both into the binary
Authentication and webhook verification are universal backend tasks. In pure JS on an interpreted engine, bcrypt is too slow and blocks the single event loop thread; via npm, native addons don’t work and pure-JS fallbacks starve I/O. Putting HMAC oncrypto.subtle and bcrypt on a tiny, zero-alloc native worker pool solves auth without a single external package.
Full reference: crypto API.
6. Postgres TLS (sslmode=verify-full) and IPv4-first resolution
What’s new
The built-in Postgres wire client (sql and new SQL(...)) now supports TLS 1.2 via BearSSL with full certificate chain and SAN verification:
- Supports
sslmode=verify-full(via DSN query param, options object, orPGSSLMODE/PGSSLROOTCERT) andsslmode=disable. - Refuses weak TLS modes: libpq’s
require,prefer, andverify-camodes (which skip hostname verification or silently downgrade) are explicitly rejected. - IPv4-first DNS resolution & byte-order fix: Fixed a network-byte-order swap bug in
resolveHostfor IPv4getaddrinforesults and updated host resolution to prefer IPv4 addresses before falling back to IPv6.
7. AbortController, AbortSignal, and structuredClone
What’s new
AbortControllerandAbortSignal: Full web-standard cancellation includingAbortSignal.abort(reason?),AbortSignal.timeout(ms),signal.throwIfAborted(), and"abort"event listeners. Integrated across:fetch(url, { signal })andnew Request(url, { signal })— aborts in-flight requests and frees the fetch slot.setTimeout(fn, ms, { signal })/setInterval— cancels the timer when aborted.http.serve({ port, signal }, handler)— triggersserver.close()when aborted.
structuredClone(value): Global deep binary clone (up to 4 MB per call) available on both the main thread and insideWorkerthreads, sharing the same serializer used bypostMessage.
Why it matters
Serverless functions run under strict wall-clock budgets. Relying on the global 30-second socket timeout means one slow upstream can eat your entire function invocation.AbortSignal.timeout(ms) gives every outbound fetch and timer a composable, per-call deadline.
Full reference: fetch API · Worker API.
8. Protocol, filesystem, and supply-chain hardening
Finally,v0.3.0-beta includes a comprehensive security and correctness pass across every I/O boundary:
- HTTP/1.1 framing strictness: Rejects duplicate or conflicting
Content-Lengthheaders,Transfer-Encoding, obsolete line folding (obs-fold), and bad whitespace (BWS) with400 Bad Request, plus a 30-second read deadline for incomplete headers or bodies. - Cross-origin
fetchhygiene & 16 MB cap: Outboundfetchnow strips sensitive headers (authorization,cookie,x-api-key) when following a redirect across origins, validates header characters per RFC 7230, and enforces a 16 MB cap on both declaredContent-Lengthand decompressed response bodies. - WebSocket hardening: Enforces RFC 6455 client frame masking on the server, caps control frames at 125 bytes, validates UTF-8 strictly on text frames, bounds the per-socket outbound buffer at 32 KB (
TX_BUF_SIZE), and uses generation-tagged{slot, gen}socket handles so a retained JS reference can never address a recycled socket slot. - No silent truncation in
fs:fs.writeFileandfs.writeFileAsyncnow throw/reject if payloads exceed the 10 MB cap instead of silently truncating. - Package containment: The module resolver and
ff imprintrejectpackage.jsonmanifest targets (main,module,exports) or bare subpaths that contain..or escape the package directory root. - Verified self-updates:
ff upgradenow downloadssha256sums.txtfrom the GitHub release and verifies the binary’s SHA-256 digest before replacingff. - Entry module auto-detection by parsing:
ff <file.js>now detects whether an entry file is an ES module or a classic script by parsing it with QuickJS rather than brittle keyword scanning.
Upgrade or install
If you already haveff installed:
v0.2.0-beta, add the --allow-* flags your app uses to your start command or Dockerfile CMD:
- Permissions — flags, scopes, and the
PermissionDeniedcontract - HTTP Server guide —
(url, method, body, headers),reusePort, and body spill cryptoAPI —crypto.bcryptandcrypto.subtleHMAC- Postgres API —
sslmode=verify-fullTLS configuration - Limitations — every hard cap in
v0.3.0-beta