diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-14 02:29:13 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-14 02:29:13 +0200 |
| commit | a1aaf31a27d1c1b65efc3c6a25fc6cc8771578ea (patch) | |
| tree | e6cd48a0385221194bf0f3290576bdfe437b4841 /packages/meshbay-node/src/meshbay_node/indexer/title_parse.py | |
| parent | 392b5e4a53aace725794c7bbabf9e95fb4e1b9c5 (diff) | |
| download | meshbay-a1aaf31a27d1c1b65efc3c6a25fc6cc8771578ea.tar.gz | |
fix(hub): Argon2 runs off the event loop, on exactly one worker
One derivation is 256 MB and a quarter to half a second of CPU (240 ms here,
485 ms on meshbay.org). All eleven call sites — sign-in, registration, the two
rehashes, passphrase change, reset and account deletion — ran it inline in an
async handler, so every one stopped the whole hub for that long: no request
served, no node socket read, no offer relayed. Measured on a local hub during
eight concurrent sign-ins, the worst `/v1/health` response went from 232 ms to
10 ms; the sign-ins themselves take the same time.
It could not simply go to a thread pool. Two concurrent `lanes=4` derivations
deadlock inside OpenSSL and never return, at no CPU — reproduced on
cryptography 50.0.x / OpenSSL 4.0.x both locally and on meshbay.org, while
`lanes=1` does not. `lanes` is part of every stored hash, so it is not ours to
change, and inline on the loop two derivations could never overlap, which is
the only reason production never hung.
So `auth.hash_password_off_loop` / `verify_password_off_loop` hand the work to
a dedicated executor with exactly one worker. Not a semaphore around
`to_thread`: a cancelled request would release its permit while its thread was
still deriving, and the next derivation would start beside it. One worker also
bounds Argon2's memory to one derivation whatever the number of callers.
`test_argon2_off_loop.py` reads every module for a direct call, pins the single
worker, runs four derivations and four sign-ins concurrently to completion, and
checks the loop keeps turning during a derivation; each fails with its guard
removed. CLAUDE.md and AV9 state the rule and the trap.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LcF3QKWii7uQ2kSyXErzCt
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/indexer/title_parse.py')
0 files changed, 0 insertions, 0 deletions