fix(sdk,transport): bounded prekey requests and a real registration retry (4.13.2)
An unreachable prekey server (packets dropped, not refused) held createShade for ~2 min per call, and a failed registration was never retried despite the log saying so. Every request now has a deadline, registration retries with backoff until it lands, and registration: 'background' lets an app open its identity offline. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -82,3 +82,44 @@ describe('ShadeFetchTransport', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* A server that drops packets instead of refusing them used to hold every
|
||||
* call until the kernel gave up on the TCP handshake — two minutes on
|
||||
* Linux. Every request now has a deadline.
|
||||
*/
|
||||
describe('ShadeFetchTransport request deadline', () => {
|
||||
/** A fetch that never answers, but honours abort like the real one. */
|
||||
const blackHole = ((_url: unknown, init?: RequestInit) =>
|
||||
new Promise<Response>((_resolve, reject) => {
|
||||
init?.signal?.addEventListener('abort', () => reject(init.signal!.reason));
|
||||
})) as unknown as typeof fetch;
|
||||
|
||||
test('a request nobody answers fails with a NetworkError at the deadline', async () => {
|
||||
const transport = new ShadeFetchTransport({
|
||||
baseUrl: 'https://prekey.invalid',
|
||||
crypto,
|
||||
fetch: blackHole,
|
||||
requestTimeoutMs: 50,
|
||||
});
|
||||
const started = Date.now();
|
||||
const err = await transport.getKeyCount('bob').catch((e) => e);
|
||||
expect(err.name).toBe('NetworkError');
|
||||
expect(err.message).toContain('No response from prekey.invalid within 50 ms');
|
||||
expect(Date.now() - started).toBeLessThan(2_000);
|
||||
});
|
||||
|
||||
test('every request goes through the supplied fetch', async () => {
|
||||
const urls: string[] = [];
|
||||
const transport = new ShadeFetchTransport({
|
||||
baseUrl: 'https://prekey.invalid',
|
||||
crypto,
|
||||
fetch: (async (url: string) => {
|
||||
urls.push(url);
|
||||
return new Response(JSON.stringify({ count: 7 }), { status: 200 });
|
||||
}) as unknown as typeof fetch,
|
||||
});
|
||||
expect(await transport.getKeyCount('bob')).toBe(7);
|
||||
expect(urls).toEqual(['https://prekey.invalid/v1/keys/count/bob']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user