Files
TREK/server/tests/unit/utils/connectAttempt.test.ts
T
Maurice 8659262e59 fix(services): let slow handshakes reach the TREK services
Node gives each address of a dual-stack name 250 ms before it moves on.
From Australia that is shorter than one round trip to Europe, so on a
network without IPv6 the IPv4 handshake to places.liketrek.com was cut
off, the IPv6 attempt failed at once and every request ended in
ETIMEDOUT. The installation never got its services key, sharing place
details stayed unavailable and searches fell back to OpenStreetMap.

Raise the per-address attempt timeout to 2 s at startup, keeping a
larger value an operator already set, and log the reason behind
undici's bare "fetch failed" for each address tried.
2026-11-02 12:12:48 +01:00

31 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { CONNECT_ATTEMPT_TIMEOUT_MS, widenConnectAttemptTimeout } from '../../../src/utils/connectAttempt';
import net from 'node:net';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
describe('widenConnectAttemptTimeout', () => {
let original: number;
beforeEach(() => {
original = net.getDefaultAutoSelectFamilyAttemptTimeout();
});
afterEach(() => {
net.setDefaultAutoSelectFamilyAttemptTimeout(original);
});
it('raises Node’s 250 ms default so a slow but working handshake is not cut off', () => {
net.setDefaultAutoSelectFamilyAttemptTimeout(250);
expect(widenConnectAttemptTimeout()).toBe(CONNECT_ATTEMPT_TIMEOUT_MS);
expect(net.getDefaultAutoSelectFamilyAttemptTimeout()).toBe(CONNECT_ATTEMPT_TIMEOUT_MS);
});
it('keeps a larger value an operator already set', () => {
net.setDefaultAutoSelectFamilyAttemptTimeout(5_000);
expect(widenConnectAttemptTimeout()).toBe(5_000);
expect(net.getDefaultAutoSelectFamilyAttemptTimeout()).toBe(5_000);
});
});