From d3b16ae0408c2c21927e2cd5055564f564daca3c Mon Sep 17 00:00:00 2001 From: unraid Date: Mon, 27 Apr 2026 17:41:23 +0800 Subject: [PATCH] fix: use a deadline timer for peer connects The raw socket handoff no longer needs Socket#setTimeout; an ordinary connection deadline keeps the timeout behavior while avoiding an internal socket timeout listener that has no reliable UDS integration path to exercise. Constraint: Keep Codecov coverage honest without adding ignore pragmas, mocks, or fallback suppression. Rejected: c8 ignore on the timeout listener | hides the uncovered branch instead of simplifying the lifecycle. Rejected: keep Socket#setTimeout listener | leaves a socket listener lifecycle to manage for a connect-only deadline. Confidence: high Scope-risk: narrow Directive: Keep connectToPeer errors caller-owned via onSocketError and reject pre-connect failures with UdsPeerConnectionError. Tested: bun test src/utils/__tests__/udsMessaging.test.ts src/services/AgentSummary/__tests__/agentSummary.test.ts Tested: bunx tsc --noEmit --pretty false Tested: bun run lint Tested: bun test src/utils/__tests__/udsMessaging.test.ts --coverage --coverage-reporter lcov --coverage-dir coverage-uds Tested: bun run test:all Tested: bun test --coverage --coverage-reporter lcov --coverage-dir coverage Tested: bun run build Tested: bun run build:vite Tested: bun audit Not-tested: Manual external ACP peer runtime beyond repository tests. --- src/utils/__tests__/udsMessaging.test.ts | 1 - src/utils/udsClient.ts | 13 ++++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/utils/__tests__/udsMessaging.test.ts b/src/utils/__tests__/udsMessaging.test.ts index 5a81916c6..8ad179d45 100644 --- a/src/utils/__tests__/udsMessaging.test.ts +++ b/src/utils/__tests__/udsMessaging.test.ts @@ -354,7 +354,6 @@ describe('UDS inbox retention', () => { expect(client.destroyed).toBe(false) expect(client.listenerCount('error')).toBe(1) - expect(client.listenerCount('timeout')).toBe(0) const socketError = new Error('post-connect failure') client.emit('error', socketError) diff --git a/src/utils/udsClient.ts b/src/utils/udsClient.ts index c282c2326..c0a32f721 100644 --- a/src/utils/udsClient.ts +++ b/src/utils/udsClient.ts @@ -280,13 +280,14 @@ export function connectToPeer( return new Promise((resolve, reject) => { const conn = createConnection(socketPath) let settled = false - const onTimeout = () => { - fail(new Error('Connection timed out')) - } + const timeout = setTimeout( + fail, + timeoutMs, + new Error('Connection timed out'), + ) function cleanupListeners(): void { - conn.setTimeout(0) + clearTimeout(timeout) conn.off('error', fail) - conn.off('timeout', onTimeout) } function fail(cause: unknown): void { if (settled) { @@ -307,8 +308,6 @@ export function connectToPeer( resolve(conn) }) conn.on('error', fail) - conn.once('timeout', onTimeout) - conn.setTimeout(timeoutMs) }) }