Two write() Calls Can Stall a TCP Connection for 40 ms

Send a header and a body as two small write() calls, then wait for a reply, and every round trip can stall for about 40 ms on an idle machine with an idle network. Neither Nagle’s algorithm nor delayed ACK is a bug; together they deadlock until a timer fires. This post predicts the stall, reproduces it with a 50-line script, reads it off a packet trace, and compares the four ways out.

September 1, 2026 | 12 min

Retries Duplicate Your Writes, and Exactly-Once Won't Save You

When a request times out, the client cannot tell whether the request or only its acknowledgement was lost. This is why exactly-once delivery cannot be built, and why effectively-once processing is at-least-once delivery plus a receiver that deduplicates. A runnable experiment with a flaky network, the bug that still duplicates 89 of 200 requests, an atomic dedupe store, and a jitter simulation.

August 28, 2026 | 16 min

A Dead TCP Peer Goes Unnoticed for 15 Minutes on Writes, Forever on Reads

TCP never tells you that the peer is gone. A reader blocks forever, a writer keeps retransmitting for a quarter of an hour, and SO_KEEPALIVE does nothing while data is unacknowledged. This post builds a one-file Linux lab with no root, climbs a ladder of mechanisms (nothing, keepalive, TCP_USER_TIMEOUT, an application heartbeat), measures how long each takes to notice, and shows where NAT and the RFCs fit in.

August 23, 2026 | 19 min

A WebSocket Stays Open After Its Token Expires

A WebSocket carries credentials once, at the handshake, and afterwards the server holds only a verdict. When the token expires or is revoked, the open socket does not change. The Origin header checked at the handshake is the browser’s statement about which page opened the socket, not proof of who is connecting. A small server that enforces expiry itself, accepts renewals under four rules, and checks Origin by exact match while always requiring a separate credential, with tests and a headless Chrome check.

August 21, 2026 | 13 min

Sending Fewer Messages over a Metered Relay

On Cloudflare Durable Objects, incoming WebSocket messages are billed and outgoing ones are not. On a relay like that, the number of messages is something you design. Three ways, with working code and tests: batch events into one frame by time, count and bytes; replace timer polling with change subscriptions and keep the poll as a fallback; and have an idle host drop its connection when nobody needs it.

August 19, 2026 | 10 min

Finding a WebSocket Whose close Never Comes, from a Phone App

A client that waited for its own socket’s close event before cleaning up stopped silently when the event never arrived. A WebSocket’s close event and readyState only tell you what the socket last reported. Three habits follow, each with working code and tests: clean up the moment you decide to close, probe only a quiet connection with an application-level ping, and on returning to the foreground, check, rebuild and catch up.

August 17, 2026 | 15 min

Behind NAT, the Machine Dials Out

When an agent lives on a machine that cannot open an inbound port, the server never connects to it. The machine reports liveness over short outbound HTTPS requests and fetches work with a separate one. Silence is kept apart from a stop, and the destination of a piece of work is fixed when it is submitted, so silence never moves it to another machine. Includes a minimal PostgreSQL version with a partial unique index and FOR NO KEY UPDATE.

August 3, 2026 | 8 min

Testing ON CONFLICT and SKIP LOCKED Takes a Real PostgreSQL

In a backend that writes SQL by hand, retry idempotency and double-claim prevention live inside ON CONFLICT and FOR UPDATE SKIP LOCKED, where a mocked database never looks. This post starts the production PostgreSQL version with testcontainers, applies the real migrations, isolates tests with TRUNCATE, and splits pytest into unit and integration lanes in CI.

July 8, 2026 | 12 min

AI Agent Clean Architecture

Why I built an AI agent platform in Go instead of using LangChain, and how Clean Architecture made model, memory, tool, and streaming concerns independently replaceable.

April 7, 2026 | 14 min