NTNT 0.6.1 adds WebSockets that are designed to disconnect

Most WebSocket demos end at the satisfying moment when the word connected appears. NTNT 0.6.1 begins the more useful argument five minutes later, when it deliberately closes the connection.

That sounds like a defect filed by an impatient clock. The limit makes the release's clearest statement: a socket is a temporary delivery path, not a place to keep the truth.

NTNT 0.6.1 was released today with native WebSocket endpoints in its asynchronous HTTP server. An application registers an endpoint, then returns websocket() from an ordinary GET route. Existing middleware and authorization run before the upgrade, and an idle connection occupies native asynchronous state rather than tying up a worker or operating-system thread.

The smallest useful version is an echo route with explicit state:

import { ws_endpoint, websocket, ws_send } from "std/http/server"

fn echo(conn, message, state) {
    let count = state["count"] + 1
    ws_send(conn, "#" + str(count) + " " + message["data"])?
    return map { "count": count }
}

let echo_endpoint = ws_endpoint("echo", echo)

get("/ws", fn(req) {
    return websocket(echo_endpoint, map {
        "state": map { "count": 0 }
    })
})

I downloaded the v0.6.1 Linux release, verified its published checksum, and ran the bundled WebSocket demo. Two messages on one connection came back as:

#1 hello
#2 again

After disconnecting and opening a new socket, the next reply was #1 new connection. The demo's protected feed also refused an unauthenticated upgrade with HTTP 401. That is a small test, not a production benchmark, but it verifies the basic shape of the released feature: ordered per-connection callbacks, state that survives from one message to the next, and authorization before a socket opens.

The reset to #1 is the important part. WebSocket state is JSON-compatible data capped at 16 KiB. It belongs to one connection. If the number mattered after a reconnect, the application would need to store it somewhere durable and load it again. The socket can carry a change; it does not become the database merely because it stays open for a while.

NTNT makes that distinction difficult to ignore. Every connection has a finite lifetime, five minutes by default and at most 24 hours. When the lifetime ends, the client reconnects, which runs middleware and authentication again. A code reload closes sockets with status 1012 so old connection state does not wander into new callbacks. A client that falls behind a broadcast can be closed with 1013, then reconnect and fetch current state.

Those omissions force an application to put durable state somewhere else and define what happens after a missed event. The release provides no cross-process broker, replay log, room protocol or automatic retry. Broadcast delivery is process-local and nondurable. Even a successful ws_send() means the message was queued, not that another machine received it. Applications still need an authoritative record and a reconciliation path.

There is also a security boundary worth keeping. A successful handshake proves that a request was authorized at that moment; it is not permanent permission. The WebSocket guide tells applications to recheck current authorization inside callbacks before performing sensitive commands. The five-minute reconnect helps expired sessions lose access, but it does not turn a handshake into continuous revocation.

The guide recommends server-sent events plus ordinary POST requests unless clients really need to send frequent messages. For pages that mostly receive updates, those simpler pieces may be enough.

Realtime software is full of events that are not very real-time at all: a laptop sleeps, Wi-Fi changes, a deployment replaces the code, or a user loses permission while a tab remains open. NTNT 0.6.1 gives those interruptions names and limits. The connection is expected to end. The application is expected to know what remains true afterward.