Repository navigation
Device discovery: per-tenant time budget, log slow and skipped tenants - #122
Merged
Merged
Conversation
/device/discover checked every tenant one after another. On a server where one tenant's directory lookup hangs, the request never answered and Cloudflare returned 520 after 120 s, so a freshly approved gateway could never join (seen on demo-server1). Tenants are now checked four at a time, each within 10 s. A tenant that does not answer in time is skipped and logged with its id; lookups over 2 s are logged too, to find the culprit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VV3yvzDYWbyjds137B8aXj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Karsten · project thread
Problem
A MindooMail gateway approved on demo-server1 could not join: every
POST /device/discoverran for exactly 120 s and then Cloudflare answered 520./device/challengeand an unsigned/device/discover(401) answer in ~0.1 s, the container did not restart and there was no OOM. The server log shows the discover loading every tenant one after another and never reaching[DeviceDiscovery] Wrapped …, so one tenant'sdirectory.getUserBySigningPublicKey()(for an unknown key it goes through the time-travel directory state) does not return. Which tenant and why is still open; this PR makes the endpoint survive it and names the tenant.Changes
DeviceDiscoveryService.discover: tenants are checked 4 at a time, each within 10 s (DeviceDiscoveryOptionsto override). A timed-out tenant is skipped and logged:[DeviceDiscovery] tenant <id>: skipped, no answer within 10000 ms. Lookups ≥ 2 s are logged with their duration.Testing
npx jest src/__tests__/DeviceDiscovery.test.ts(5 passed),src/__tests__/ServerCoreInMemory.test.ts(5 passed)tsc --noEmitFollow-up
Once deployed, the log names the hanging tenant; if it is the tenant the gateway was approved in, the gateway is skipped there too and the directory hang itself needs fixing.
Generated by Claude Code