chadtmiller.com/monolith
An atproto PDS
0
0
Spaces' issuer keys renewed in the background; PLC reads reuse connections
Merged Approved
This keeps spaces' issuer keys for PDS_DID_CACHE_SECS. Once a key is half that old, it renews the key in the background. It reads each issuer's document once at a time. It also reads PLC documents over a pooled client that retries once on a connection of its own. I read the whole diff and found no defects.
- Behaviour in code: Turn handling is sound. The key is stamped with the time its read began, so a late write can't make a key look younger than it is. A failed renewal leaves the old key in place.
PDS_DID_CACHE_SECS=0keeps nothing and reads every time, as the spec says. - Spec: The change is in
SPACES-CREDENTIALS.mdandLIMITS.md, with the "Connections" bullet and the harness descriptions. The changeset is written for operators. - Harness: The new checks only add strictness.
issuers.mjsruns against the server alone, and it states what it compares in each case. The proxy change only adds recording. - Docs:
docs/has no mention ofPDS_DID_CACHE_SECS, so there is no guide to update.
Minor, no change needed: while the directory is down, every call that finds a half-old key spawns another renewal. Each runs one at a time and the PLC turn limits them, so this is bounded.
All checks have passed
4 passed, 1 skipped
4 passed checks
citationsSuccess in 0sdocsSuccess in 22sgatesSuccess in 0srelease-pullSuccess in 12s1 skipped check
releaseSkippedMerged as 7425de9
In production, 7.7% of
authorizeSpaceSynccalls waited about 350 ms for the PLC directory. Together they made up 254 of its 300 s of server time. This keeps spaces' issuer keys forPDS_DID_CACHE_SECSand renews them in the background, with one read per issuer at a time. Reads from the directory now reuse an open connection.Claude Opus 5.5 · high
What changes
Spec.
SPACES-CREDENTIALS.md, "Issuers' keys": an issuer's key is kept forPDS_DID_CACHE_SECS, not a fixed 5 minutes. Once a key is half that old, a token it verifies is answered at once and the issuer's document is read again afterwards. A key unused for the whole ofPDS_DID_CACHE_SECSis read again before it is used. Each issuer's document is read once at a time, and calls that need it meanwhile wait for that read. Reading again when a signature fails against a kept key is unchanged.LIMITS.md: thePDS_DID_CACHE_SECSrow names issuer keys, and "The PLC directory" gains Connections. A read goes over a connection an earlier read left open, kept up to 90 s. A read that fails on its way is sent once more over a connection of its own. A post always takes a connection of its own.Harness.
harness/spaces/issuers.mjsruns in the spaces run after the guard, against the server alone. It starts the server withPDS_DID_CACHE_SECS=6and makesdid:webissuers whose documents a harness listener serves, recording each read:In the limits run,
plcConnectionsmakes 6 accounts one after another through the PLC proxy, which now records the requests each connection carried. Each post must be the first request on a connection of its own, and the reads must take fewer connections than there are reads.pds-server.
space_credentials::jwt::Keyskeeps each key with the time its read began, and gives each issuer a turn (a per-issuer async mutex, asblobstore's turns are). A stale key that verifies spawnsrenew, which reads unless another read is under way or one has ended since. The credential paths take&Sharedso thatrenewcan be spawned.plc::documentreads over a pooled client (90 s idle) and retries over the caller's no-idle client. Posts keepplc::client().Why
From monolith.chadtmiller.com, over 4.4 h of its log and 52 h of
/metrics:pds_outbound_request_duration_seconds{target="plc"}averaged 362 ms over 8,427 reads, and none took under 250 ms.authorizeSpaceSynccalls came in bursts every 5 minutes, atKEY_KEPT = 300. Up to 8 of them arrived in the same millisecond and made 8 separate reads.Considered: verifying the server's own accounts' tokens with the key the server holds, skipping the read altogether. Once keys are renewed in the background, that saves no call any wait, only background reads, and it adds a second path with its own rules for accounts that rotate keys or move away. So it is left out.
Kept: a rotated-to key is still taken at once, because a failed signature forces a read. A key rotated away from is now taken for up to
PDS_DID_CACHE_SECS(an hour by default) rather than 5 minutes. That matches how long the server already keeps account and service-token documents.How it was checked
main(cc1f0b6).issuers.mjs: 8 reads, not 1; no renewal; no read once the key was past its time.plcConnections: 6 reads over 6 connections.issuers.mjswas run on its own against a lone server through a throwaway driver (removed). The limits run was run with--only plcDocuments,plcAtOnce,plcConnections.cargo test -p pds-server --lib -- space_credentials plc:: space_notify identity::passes.a_rotated_key_is_read_againnow setsdid_cache = 3600, since the test config's 0 keeps no key.just quickpasses here (all 7 runs). The full gates are thegatesworkflow on this pull.Shortcomings
PDS_DID_CACHE_SECS. The default hour is not run.getBlobwaits about 100 ms on R2, and the blobstore and outbound clients keep connections idle only 2 s.Review
Start at
verify_issuerandrenewincrates/pds-server/src/space_credentials/jwt.rs, then the "Issuers' keys" paragraph.