{"record":{"id":"e1e3dc2f893a55df","repo":"docmirror/dev-sidecar","slug":"speed-test-by-tcp-timeout","errorCode":null,"errorMessage":"[speed] test by TCP timeout:","messagePattern":"\\[speed\\] test by TCP timeout:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/mitmproxy/src/lib/speed/SpeedTester.js","lineNumber":258,"sourceCode":"        clearTimeout(timeoutId)\n\n        const connectionTime = Date.now()\n        resolve({ status: 'success', by: 'TCP', target: `${host}:${this.port}`, time: connectionTime - startTime })\n        client.end()\n      })\n      client.on('error', (e) => {\n        isOver = true\n        clearTimeout(timeoutId)\n\n        log.warn('[speed] test by TCP error:  ', this.hostname, `➜ ${host}:${this.port} from DNS '${dns}', cost: ${Date.now() - startTime} ms, errorMsg:`, e.message)\n        reject(e)\n        client.destroy()\n      })\n\n      timeoutId = setTimeout(() => {\n        if (!isOver) {\n          isOver = true\n          log.warn('[speed] test by TCP timeout:', this.hostname, `➜ ${host}:${this.port} from DNS '${dns}', cost: ${Date.now() - startTime} ms`)\n          reject(new Error('timeout'))\n          client.destroy()\n        }\n      }, timeout)\n    })\n  }\n\n  // 暂不使用\n  // testByPing (item) {\n  //   return new Promise((resolve, reject) => {\n  //     const { host, dns } = item\n  //     const startTime = Date.now()\n  //\n  //     // 设置超时程序\n  //     let isOver = false\n  //     const timeout = 5000\n  //     const timeoutId = setTimeout(() => {\n  //       if (!isOver) {","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/docmirror/dev-sidecar/blob/7710cd56cce760c708f30b01d2d4056eb8c402d5/packages/mitmproxy/src/lib/speed/SpeedTester.js#L240-L276","documentation":"SpeedTester's testByTCP opens a raw TCP connection to a candidate host:port to measure latency/availability. If the connection doesn't complete within the timeout window, the pending test is rejected with Error('timeout') and this warning is logged with the target, DNS source, and elapsed cost. The failed IP will score badly and lose the speed-test selection.","triggerScenarios":"testOne -> testByTCP against an IP whose TCP port doesn't respond within `timeout` ms — blocked by firewall, filtered by GFW, dead server, or a very slow route; the socket neither connects nor errors before the timer fires.","commonSituations":"Testing candidate IPs for github/docker domains from networks where those IPs are blocked; IPv6 addresses on IPv4-only networks; extremely congested links; timeout configured too low for high-latency mobile networks.","solutions":["Increase the speed test timeout in config (speed test timeout option) if your network is high latency (e.g. mobile/VPN).","Prune unreachable or blocked IPs from your pre-set ip lists so they aren't repeatedly tested.","Check local firewall/VPN rules that silently drop (rather than reject) TCP SYN packets to the tested ports.","Ignore occasional timeouts — the tester is designed to reject slow endpoints and pick better IPs automatically."],"exampleFix":"// before\n\"speedTest\": { \"timeout\": 2000 }\n// after\n\"speedTest\": { \"timeout\": 5000 }","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await speedTester.testOne(ip, port) } catch (e) { if (e.message === 'timeout') markIpUnavailable(ip) }","preventionTips":["Set a generous speed-test timeout for high-latency networks","Remove known-blocked IPs from candidate lists","Check firewall rules that silently drop SYN packets","Treat occasional timeouts as normal selection signal, not an outage"],"tags":["speed-test","tcp","timeout","network"],"backgroundTag":"tcp-connect-timeout","analyzedSha":"7710cd56cce760c708f30b01d2d4056eb8c402d5","analyzedAt":"2026-08-31T22:07:07.234Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}