Liking cljdoc? Tell your friends :D

2026-11-23 — Three faults in an instance alone, found while reviewing the gateway

Two rounds of review of the gateway work (unreleased, on its own branch) turned up three faults that are not the gateway's. They are fixed here, on the base, ahead of it. The suite went from 127 tests to 134, 516 assertions.

A cancellation could stop another client's eval. notifications/cancelled names a request by its JSON-RPC id, and the table of requests in flight was keyed by that id alone — since the table was written, so in every release with explicit cancellation. Clients number their requests from a low number each: two with request 5 in flight shared one entry, the later overwriting the earlier, and either's cancellation stopped whichever was there.

A first fix keyed the table by the id within its sender and declined a cancellation naming two requests. The second round showed that this was not enough: a request was on the books only while it waited on its eval, so one that had finished waiting and was rendering its answer did not count, and a cancellation meant for it found its namesake alone and stopped that. The mark recording a cancellation sat under the shared key as well, where a later request by the same id could read it.

As it stands now: the transport puts each request on the books before dispatching it and takes it off after the response is written or the write has failed; a request has a record of its own, which carries both the thunk that cancels what it waits on and the mark that it was cancelled; a cancellation acts only when its id names exactly one record. A cancellation that arrives before the request has begun to wait is acted on when it does.

What it cannot do: two clients on one machine speaking the stateless wire are told apart by nothing. The wire has no connection, and the notice carries no session. With the same id in flight from both, neither is cancelled.

A session released while its eval ran came back. The eval's ending records the namespace it ended in, and that write did not check that the session was still there. Liveness is the presence of a row, so the handle was live again — refused one moment, accepted the next, with no scratch, no client record and no last-seen stamp, which also made it the first thing the next reap released. Reachable today only by expiry catching a session mid-eval, which takes an eval that runs for over a day while its session says nothing; the gateway, which retires handles at any moment, is what made it matter.

Going through every writer in session found one more of the kind, the client record written at creation. Both are guarded. Two neighbours of the same fault turned up on the way and are closed with it: (__r/scratch! …) called by an eval whose session had ended furnished a compartment nobody would reap, and an eval beginning for a session already gone furnished the main scratch likewise. Both now fail and say the session has ended.

A session from before handles lost track of its scratch across a reload. Up to 0.9.0 a session on the legacy wire went by its connection's UUID and its scratch by the id's first eight letters and digits. The one-session change named the scratch by the whole id. The session table survives a reload, so such a session's scratch was no longer found: not listed, and left interned when the session ended. The eight-character rule is back; a handle is shorter than eight, so it names itself under either.

On the tests. Six were added. Run against the source as it was, four fail — thirteen assertions — and the other two cannot be compiled there, since they drive the admission the old code does not have. One of the six goes through the real transport: two connections from one address, each with request 1 in flight, and a cancellation on one of them.

Not tried: a client cancelling through the transport at the instant its response is being written. The books cover that window by construction, and nothing here holds a write open to prove it.

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close