| … | … | @@ -530,7 +530,18 @@ export class DidPeerRouter { |
| 530 | 530 | if (!this._byDid.has(did) || this._byDid.get(did).size === 0) await this._waitForDid(did, timeout || 20000) |
| 531 | 531 | const entries = this._byDid.get(did) || new Map() |
| 532 | 532 | await Promise.all([...entries.keys()].map((fh) => this._ensureFront(did, fh).catch(() => null))) |
| 533 | | const best = this._freshestFront(did) |
| 533 | // A front is opened once provide() kicks off replication, but its head is only set once the firehose |
| 534 | // commit REPLICATES + verifies (event-driven, on 'append'). For a single front() call (no retry — a |
| 535 | // real getRepo request), wait for AT LEAST ONE co-owner to reach a verified head, then serve the |
| 536 | // freshest among those ready. A slow co-owner never delays serving from a ready one (freshest-of-ready). |
| 537 | let best = this._freshestFront(did) |
| 538 | if (!best) { |
| 539 | const end = Date.now() + (timeout || 20000) |
| 540 | while (!best && Date.now() < end) { |
| 541 | await new Promise((r) => setTimeout(r, 100)) |
| 542 | best = this._freshestFront(did) |
| 543 | } |
| 544 | } |
| 534 | 545 | if (!best) throw new Error(`DidPeerRouter: no frontable co-owner for ${did}`) |
| 535 | 546 | return best |
| 536 | 547 | } |