{"record":{"id":"6e5f8f2f51b6312e","repo":"apache/beam","slug":"timed-out-waiting-for-service-after-timeoutms-ms","errorCode":null,"errorMessage":"Timed out waiting for service after ${timeoutMs}ms.","messagePattern":"Timed out waiting for service after (.+?)ms\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"sdks/typescript/src/apache_beam/utils/service.ts","lineNumber":196,"sourceCode":"      }\n      await new Promise((r) => setTimeout(r, iterMs));\n      try {\n        await new Promise<void>((resolve, reject) => {\n          const socket = net.createConnection(port, host, () => {\n            connected = true;\n            socket.end();\n            resolve();\n          });\n          socket.on(\"error\", (err) => {\n            reject(err);\n          });\n        });\n      } catch (err) {\n        // go around again\n      }\n    }\n    if (!connected) {\n      throw new Error(\n        \"Timed out waiting for service after \" + timeoutMs + \"ms.\",\n      );\n    }\n  }\n}\n\nexport function serviceProviderFromJavaGradleTarget(\n  gradleTarget: string,\n  args: string[] | undefined = undefined,\n): () => Promise<Service> {\n  return async () => {\n    let jar: string;\n    const serviceInfo = serviceOverrideFor(gradleTarget);\n    if (serviceInfo) {\n      if (serviceInfo.match(/^[a-zA-Z0-9.]+:[0-9]+$/)) {\n        return new ExternalService(serviceInfo);\n      } else {\n        jar = serviceInfo;","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/typescript/src/apache_beam/utils/service.ts#L178-L214","documentation":"portReady polls the service's TCP port until timeoutMs elapses. If the process is still alive but the port never accepts a connection within the timeout, the launcher gives up and throws. The service is presumably starting too slowly or failed to bind its port while remaining alive.","triggerScenarios":"Starting a Java/Python expansion or job service on a slow machine or under heavy load; service bound to a different host than the one polled; timeoutMs set too low in start().","commonSituations":"First run of a large fat-jar with cold JIT/class loading; container resource limits slowing startup; service misconfigured to listen on localhost vs a container hostname.","solutions":["Increase the timeout (pass a larger timeoutMs to start()/service options).","Verify the service's host/port configuration matches what the SDK polls.","Check service logs for binding errors or slow startup warnings.","Pre-warm/reuse the service instead of restarting per pipeline."],"exampleFix":"// before\nawait service.start({timeoutMs: 5000});\n\n// after\nawait service.start({timeoutMs: 60000});","handlingStrategy":"retry","validationCode":"// confirm the endpoint is bindable/reachable before start\nawait checkHostResolves(host);\nawait checkPortFree(host, port);","typeGuard":null,"tryCatchPattern":"let started;\nfor (const timeoutMs of [10000, 30000, 60000]) {\n  try { started = await service.start({timeoutMs}); break; }\n  catch (e) {\n    if (!/Timed out waiting for service/.test(String(e))) throw e;\n  }\n}","preventionTips":["Set generous timeouts on slow or resource-limited machines.","Ensure host/port configuration matches where the service actually binds.","Reuse long-lived expansion services instead of cold-starting per run."],"tags":["timeout","service-startup","network"],"backgroundTag":"request-timeout","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}