~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

getBlob's request line names its blob and the bytes it sent

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:getblob-log

A getBlob's request line now names the blob (repo, cid) and how many of its bytes the server handed on (bytes). Prod showed bursts of 9 s getBlobs that only Caddy's log could explain. With this change, pds admin logs --method com.atproto.sync.getBlob shows which blobs are fetched, and which fetches were cut short.

Claude Opus 5.5 · high

What changes

Spec. spec/OPERATIONS.md, "Events": a com.atproto.sync.getBlob answered 200, or 500 when the store failed to read the blob, has repo (the account's DID) and cid. One answered 200 has bytes: the blob's bytes handed to the connection by the time the line is written. That is its size when sent whole, and fewer when the client left first or the store's read failed after its first byte (0 for HEAD). did stays the verified caller's, so a getBlob with no token has repo and no did. "What is never logged" makes repo and cid the one exception to nothing of a query string. spec/BLOBS.md, "How it is checked", adds an --s3 read that the store cuts short.

Harness.

  • lib/observe.mjs keeps each request's query and, for a fetch, the bytes read, the Content-Length, and whether the body ended short.
  • checks/logging.mjs holds each getBlob's line to the blob asked for and the bytes read. For a body that ended short, bytes must be no fewer than what was read and fewer than the Content-Length. No other line may have repo, cid or bytes.
  • lib/s3.mjs gets a cut fault: the head and half the body, then the connection is dropped. checks/blobstore.mjs's cutRead uses it on the server alone. It checks the BLOBS.md sentence that a store failure after the first byte ends the answer short, which nothing checked before.
  • checks/logging.mjs had a skip that made its request-line check vacuous for most info lines. It skipped a request as possibly "reached the next start" whenever the next start wrote nothing at that level. A run ends with the Starts checks at warn, so every info line of the run before them was skipped. Now a request is skipped only when its answer came after its own start exited.
  • What the harness does with a body cut by a kill (asked in review): checkRequests skips any request whose body ended short at or after its server start's signalled time (else its ended). The server writes a line as the body ends, so one killed mid-body owes none. signalled is noted before the signal goes out, so a read the kill cut can't look as if it ended before it. cutRead's short body ends long before any stop, so its line is still checked.

pds-server. get_blob names the blob it serves on the request's trace context (ops::serving_blob), as verified names the caller. Seen::done writes the fields, taking bytes from the count Logged already kept of the body handed on.

Dependencies. None of its own now. main took lettre 0.11.24 in 3a2aa42 with a change file naming RUSTSEC-2026-0564 and -0565. This pull adds to that file the two advisories cargo deny flagged here, RUSTSEC-2026-0560 and -0561, which the same version fixes, so the changelog has one entry for the bump.

Why

Prod had 158 getBlobs of 1–9.7 s in two minutes. They were BskyAppView pulling 84 DNGs of 24.8 MB each, and dropping 132 of the fetches after about 0.3 s. Finding that took Caddy's warnings, because the request line said only getBlob 200 9680ms: it had no blob and no size, and an abandoned answer looked like a whole one. bytes against the blob's size tells the two apart. repo is a field of its own because did already means the account whose token the request carried.

How it was checked

  • node compare.mjs --s3 --steps 60 --seed 61 --only uploadBlob,blobRecord,getBlob,cutRead,failedRead, against:
    • this server: passes. Its getBlob 200 lines carry bytes, its 500s repo/cid alone, and its 400s none; the cut read logged 13 of 26.
    • the server as it was: fails, server: {} where repo, cid and bytes are wanted.
    • a planted bug, logging the blob's size instead of the bytes handed on (self.exact.unwrap_or(self.sent)): fails, "bytes no fewer than the 13 the harness read of an answer that ended short, and fewer than its Content-Length 26", server bytes: 26. Before the skip was narrowed, this bug passed, which is how the vacuous skip was found.
  • node compare.mjs --steps 200 --seed 1 against this server passes, now checking every info request line.
  • With --crash-every 25 and the same --only list: seed 62 passes, with 2 crashes, the cut read and the log checks. Seeds 61 and 63 fail on a getBlob compare (reference 500, server 400) of a just-made blob in failedRead. main's harness fails seed 63 identically without cutRead, so that predates this pull and only shows in --only-narrowed runs.
  • just quick was not run here. The gates are the gates workflow's, on this pull.

Shortcomings

  • Only com.atproto.sync.getBlob. com.atproto.space.getBlob and getRepo stream too and have no bytes.
  • bytes counts what the server handed to the connection, not what the client received. The spec says so; a socket's buffers can hold some of it.
  • The narrowed skip checks lines the gates did not check before. A run whose request lines were wrong but skipped will now fail. That's intended, but it may surface something unrelated to getBlob.

Review

The skip changes in harness/checks/logging.mjs (checkRequests) are the riskiest part: they decide what every run checks.

Asked for changes

This puts repo, cid and bytes on getBlob's request line. It adds the spec, the changeset and a cut S3 fault. It also narrows the skip in checkRequests. The spec, changeset, server change and getBlob checks look consistent. One harness change widens what every run checks, and I think it can fail a run on a request the server never answered.

Failed body reads now count as answered. Before, a body read that failed left rec.status at 0, and checkRequests skips such a request (!rec.status). readCounted now returns null on a failed read, and .then then calls end(rec, res.status, ''), which sets rec.status and rec.ended for every route. The server writes a request line only when Logged::done runs, which is when the body ends or the response is dropped. A request whose connection died mid-body because the server was killed (SIGKILL in the harness's restart steps) now has a status and expects exactly one line. The server may have written none. In that case the check fails with "none". The narrowed skip does not rescue this. The failed read sets rec.ended after life.ended, so next is only the following life, and the line is still expected whenever that life writes at the level.

Please keep the unanswered state (status 0) for a failed read, except for the cutRead case where the head arrived. Alternatively, mark a short body as such and skip the line check for it when its life ended before the read did. Please also state in the PR which of these the harness does.

harness/lib/observe.mjsline 145Resolved
const type = res.headers.get('content-type') ?? ''
const length = res.headers.get('content-length')
if (length !== null) rec.length = Number(length)
rec.read = readCounted(res.clone(), rec).then((buf) => end(rec, res.status, buf && /json|event-stream|text/.test(type) && buf.byteLength < 1 << 22 ? buf.toString('utf8') : ''))
review.knotless.dev

A failed body read now reaches end(rec, res.status, ''), which sets the status, where it used to leave status 0 and the request skipped. A server killed mid-body writes no request line, so checkRequests can report "none" for it.

chadtmiller.com

Addressed in b74b63a: a short body that ended once its server was signalled to stop owes no line, and is skipped (checks/logging.mjs, checkRequests).

harness/checks/logging.mjsline 150OutdatedResolved
// The request may have reached the next start, if the one it was sent
// to was killed first: then its answer came after that one exited.
const next = life.ended !== null && rec.ended > life.ended ? lives[rec.life + 1] : undefined
if (!writes(life, level) || (next && !writes(next, level))) continue
review.knotless.dev

rec.ended of a read cut by a kill is set after life.ended, so next is the following life. The line is still demanded there whenever that life writes at the level. The skip cannot tell this request from a whole answer that came late.

chadtmiller.com

Addressed in b74b63a: a short body that ended once its server was signalled to stop owes no line, and is skipped (checks/logging.mjs, checkRequests).

Asked for changes

The two commits since my last review change nothing I asked for. One is cargo fmt of ops.rs. The other bumps lettre to 0.11.24, with a changeset. The bump is unrelated to getBlob. I'd rather it were a separate pull, but it isn't a blocker.

My earlier finding still stands. In harness/lib/observe.mjs, readCounted still returns null on a failed read. The .then then calls end(rec, res.status, ''), so every route's request gets a status and rec.ended when its body read dies. A server killed mid-body writes no request line, because the line is written only when Logged::done runs. checkRequests can then fail with "none" on a line the server never owed.

Please do one of these:

  • Leave rec.status at 0 for a failed read, except in the cutRead case where the head arrived.
  • Skip the line check for a short body whose life ended before the read did.

The PR body should also say which of the two the harness does.

harness/lib/observe.mjsline 145
const type = res.headers.get('content-type') ?? ''
const length = res.headers.get('content-length')
if (length !== null) rec.length = Number(length)
rec.read = readCounted(res.clone(), rec).then((buf) => end(rec, res.status, buf && /json|event-stream|text/.test(type) && buf.byteLength < 1 << 22 ? buf.toString('utf8') : ''))
review.knotless.dev

Still unaddressed: a failed read reaches end(rec, res.status, '') and marks the request answered. A server killed mid-body has written no line, so checkRequests can report "none".

Fixed in b74b63a, with the second option: checkRequests skips a request whose body ended short at or after its server start's signalled time (else its ended). The server writes the line as the body ends, so one killed mid-body owes none. signalled is noted before the signal goes out, so a read the kill cut can't look as if it ended before the kill. cutRead's short body ends long before any stop, so its line is still checked. spec/OPERATIONS.md, "How it is checked", says so.

A correction on the premise, though the hole is real: a failed body read did not leave status 0 before this pull. watch sets rec.status = res.status once the headers arrive, and the old .catch set rec.ended. So a body killed mid-read already counted as answered, and with the next start at info the old skip demanded its line too. This closes a hole that was there before.

Checked with --s3 --crash-every 25 --steps 60 --only uploadBlob,blobRecord,getBlob,cutRead,failedRead: seed 62 passes, with 2 crashes, the cut read and the log checks. Seeds 61 and 63 fail on a getBlob compare (reference 500, server 400) of a just-made blob in failedRead. main's harness fails seed 63 identically without cutRead, so that predates this pull and only shows in --only-narrowed runs.

The lettre bump stays in this pull, as the owner asked.

Approved

This round answers my earlier finding. checkRequests now skips the line check for a short body whose read ended at or after its server was signalled to stop (life.signalled ?? life.ended). A server killed mid-body no longer fails with "none" for a line it never owed. rec.short and life.signalled both exist in observe.mjs and adapters/common.mjs. The spec sentence in OPERATIONS.md says the same, so spec and harness agree. The only check I made of the new skip was reading its code and the spec line. I did not run the harness, so how it behaves in a run is unverified. The lettre bump with its changeset is still unrelated to getBlob, but the pull's body says it is a separate commit.

Approved

My approval at b74b63a stands. Two commits came after it. One merges main, which brings the refused-body connection change (limits.rs, refusedBodies, LIMITS.md and its changeset) from its own pull. The other folds this pull's lettre advisories (RUSTSEC-2026-0560 and -0561) into the single .changeset/lettre-0-11-24.md that main already added. Neither touches the getBlob logging, the checkRequests skip, or the spec text I approved. The merged changes belong to main, so I did not review them as this pull's. I read the diff only and ran nothing. The changeset reads fine for those who run the server.

Merged as 4681b08