karatelabs/karate · error · RuntimeException
stop() failed
Error message
stop() failed: {message} What it means
karate.stop() pauses the test (waiting for a socket/enter signal) and wraps any exception during that wait in 'stop() failed: <message>'. It means the stop/wait mechanism itself errored — e.g. the internal server socket could not be created, bound, or awaited.
Solutions
- Check the nested cause message for the underlying socket/IO problem
- Verify no other process holds the stop-port (lsof/netstat) and free it
- Avoid karate.stop() in CI; guard it with an env check so it only runs during local debugging
Example fix
// before
karate.stop();
// after
if (karate.get('env') == 'local') karate.stop(); Defensive patterns
Strategy: try-catch
Validate before calling
// Check a local port is bindable before stopping
if (karate.env != 'local') karate.logger.info('skipping karate.stop() in non-local env'); Try / catch
try {
karate.stop();
} catch (Exception e) {
karate.logger.warn('stop failed (continuing): {}', e.getMessage());
} Prevention
- Never call karate.stop() in CI pipelines — guard on karate.env
- Ensure the debug port is free before running
- Read the nested cause to identify socket bind problems
When it happens
Trigger: Calling karate.stop() when the internal listening socket cannot be opened (port in use, permissions) or the wait is interrupted/fails mid-flight.
Common situations: Running karate.stop() in CI where the pause port is blocked by firewall or another process holds the port; restricted containers disallowing socket binds.
Related errors
- pretty() needs one argument
- failed to find free port
- karate.debug.port is set but karate-ide JAR is not on the…
- failed to hot reload step
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/ea3643dacf8135e0.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java:1044
port = Integer.parseInt(args[0].toString());
}
}
try (java.net.ServerSocket serverSocket = new java.net.ServerSocket(port, 1,
java.net.InetAddress.getByName("127.0.0.1"))) {
int actualPort = serverSocket.getLocalPort();
System.out.println("*** waiting for socket, type the command below:\ncurl http://localhost:"
+ actualPort + "\nin a new terminal (or open the URL in a web-browser) to proceed ...");
// Block until a connection is received
try (Socket clientSocket = serverSocket.accept()) {
// Send a simple HTTP response
java.io.OutputStream out = clientSocket.getOutputStream();
out.write("HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK".getBytes());
out.flush();
}
logger.info("*** exited socket wait successfully");
return true;
} catch (Exception e) {
throw new RuntimeException("stop() failed: " + e.getMessage(), e);
}
};
}
// ========== Wait Utilities ==========
/**
* karate.waitForHttp(url) - Wait for an HTTP endpoint to become available.
* Polls until a successful response (2xx or 3xx) is received.
*/
static JavaInvokable waitForHttp() {
return args -> {
if (args.length == 0) {
throw new RuntimeException("waitForHttp() needs a URL argument");
}
String url = args[0] + "";
int timeoutMs = 30000;
int pollMs = 250;View on GitHub (pinned to a22eb90246)