Bound every connect attempt at 10 s by default, with false the way to opt out
Mirror / push (push) Successful in 5s
Test / lint (pull_request) Successful in 21s
Test / test (18) (pull_request) Successful in 19s
Test / test (20) (pull_request) Successful in 19s
Test / test (22) (pull_request) Successful in 19s
Test / test (24) (pull_request) Successful in 20s
Test / test (26) (pull_request) Successful in 19s

This commit is contained in:
2026-09-20 20:34:53 +02:00
parent 8f416c2bc4
commit 1416615ca3
8 changed files with 44 additions and 35 deletions
+6 -5
View File
@@ -22,7 +22,7 @@ export type ClientOptions = {
addrNpi?: number;
addrTon?: number;
bindType?: BindType;
connectTimeout?: number;
connectTimeout?: number | false;
enquireLinkInterval?: number;
host?: string;
idleTimeout?: number;
@@ -41,8 +41,9 @@ export type ClientOptions = {
username?: string;
};
const defaults = {
export const defaults = {
bindType: 'transceiver',
connectTimeout: 10_000,
enquireLinkInterval: 20_000,
host: 'localhost',
/** The idle timeout is what notices a dead link, so it has to outlast one silent probe. */
@@ -55,11 +56,11 @@ const defaults = {
function armConnectTimeout(
sock: Socket,
connectTimeout: number | undefined,
connectTimeout: number | false,
peer: string,
settle: (result: Result<{ sock: Socket }>) => void,
): NodeJS.Timeout | undefined {
if (connectTimeout === undefined) return undefined;
if (connectTimeout === false) return undefined;
// A firewall and a stalled handshake need different answers, and only the phase tells them apart.
let phase = `connecting to ${peer}`;
@@ -73,7 +74,7 @@ function armConnectTimeout(
}
function openSocket(options: ClientOptions): Promise<Result<{ sock: Socket }>> {
const connectTimeout = options.connectTimeout;
const connectTimeout = options.connectTimeout ?? defaults.connectTimeout;
const host = options.host ?? defaults.host;
const port = options.port ?? defaults.port;
const secure = options.tls !== undefined && options.tls !== false;
+2 -2
View File
@@ -171,12 +171,12 @@ function limitsOf(options: CheckableOptions): [string, number, number][] {
const maxTimerDelay = 2_147_483_647;
function checkConnectTimeout(connectTimeout: unknown): VoidResult {
if (connectTimeout === undefined) return {};
if (connectTimeout === undefined || connectTimeout === false) return {};
const got = typeof connectTimeout === 'string' ? `"${connectTimeout}"` : namedValue(connectTimeout);
if (typeof connectTimeout !== 'number' || !Number.isInteger(connectTimeout) || connectTimeout < 1) {
return { err: new Error(`connectTimeout must be a whole number of milliseconds, 1 or more, got ${got}; omit it or pass undefined to wait the OS out`) };
return { err: new Error(`connectTimeout must be a whole number of milliseconds, 1 or more, got ${got}; false waits the OS out instead`) };
}
if (connectTimeout > maxTimerDelay) {