{"record":{"id":"9f672ecb46eb9e9c","repo":"karatelabs/karate","slug":"http-endpoint-not-available-url","errorCode":null,"errorMessage":"HTTP endpoint not available: {url}","messagePattern":"HTTP endpoint not available: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java","lineNumber":1099,"sourceCode":"                            .timeout(Duration.ofMillis(pollMs))\n                            .GET()\n                            .build();\n                    var response = httpClient.send(request, java.net.http.HttpResponse.BodyHandlers.discarding());\n                    int status = response.statusCode();\n                    if (status >= 200 && status < 400) {\n                        return true;\n                    }\n                } catch (Exception e) {\n                    // Connection failed, continue polling\n                }\n                try {\n                    Thread.sleep(pollMs);\n                } catch (InterruptedException e) {\n                    Thread.currentThread().interrupt();\n                    return false;\n                }\n            }\n            throw new RuntimeException(\"HTTP endpoint not available: \" + url);\n        };\n    }\n\n    /**\n     * karate.waitForPort(host, port) - Wait for a TCP port to become available.\n     * Polls until a TCP connection can be established.\n     */\n    static JavaInvokable waitForPort() {\n        return args -> {\n            if (args.length < 2) {\n                throw new RuntimeException(\"waitForPort() needs host and port arguments\");\n            }\n            String host = args[0] + \"\";\n            int port;\n            if (args[1] instanceof Number) {\n                port = ((Number) args[1]).intValue();\n            } else {\n                port = Integer.parseInt(args[1].toString());","sourceCodeStart":1081,"sourceCodeEnd":1117,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java#L1081-L1117","documentation":"After polling the HTTP endpoint for the full timeout (default 30s) without ever receiving a 2xx/3xx response, karate.waitForHttp() gives up and throws this error naming the URL. It signals the endpoint never became available during the wait window.","triggerScenarios":"karate.waitForHttp(url) where the server never starts, listens on a different host/port, returns only 4xx/5xx, or the timeout (configurable via the second Map argument) is too short for a slow service.","commonSituations":"Docker compose services not yet up during integration tests; wrong port in the health URL; app crashing on startup; CI runners with slow cold starts exceeding the 30s default.","solutions":["Verify the URL/host/port is correct and the service actually listens there","Increase the timeout via the options map, e.g. { timeoutMs: 120000 }","Check application startup logs for crashes or slow initialization","Confirm the endpoint returns 2xx/3xx (4xx/5xx responses are not treated as success)"],"exampleFix":"// before\nkarate.waitForHttp('http://localhost:8080/health');\n// after\nkarate.waitForHttp('http://localhost:8080/health', { timeoutMs: 120000, pollMs: 500 });","handlingStrategy":"retry","validationCode":"// Pre-check the endpoint manually before committing to a long wait\ncurl -s -o /dev/null -w '%{http_code}' http://localhost:8080/health","typeGuard":null,"tryCatchPattern":"try {\n    karate.waitForHttp(url, { timeoutMs: 60000 });\n} catch (Exception e) {\n    karate.logger.error('endpoint {} never became ready — check service logs', url);\n    throw e;\n}","preventionTips":["Size timeoutMs to the service's worst-case startup time","Ensure the health endpoint returns 2xx/3xx","Verify host/port from the test runner's network perspective (containers vs host)","Watch service startup logs while the poll runs"],"tags":["http","timeout","polling","availability"],"backgroundTag":"http-error-response","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}