Gatling "j.n.ConnectException: Connection refused" in CI
Gatling reports every request as KO with "j.n.ConnectException: Connection refused" when the target host actively refuses the TCP connection. In CI this means the service under test was not up, or the baseUrl points somewhere nothing is listening.
What this error means
The run shows 100% KO and the error table is dominated by "j.n.ConnectException: Connection refused: localhost/127.0.0.1:8080". No successful requests are recorded.
---- Errors --------------------------------------------------------------------
> j.n.ConnectException: Connection refused: localhost/127.0.0.1:8080 5000 (100.0%)Common causes
The service under test is not listening
Gatling started before the app or container began accepting connections, so every request is refused.
The baseUrl points at the wrong host or port
A baseUrl of localhost when the app runs in a service container, or a port that is not published, means nothing accepts the connection.
How to fix it
Wait for readiness before Gatling runs
- Poll the target health endpoint until it responds.
- Run the Gatling simulation only after the target is confirmed up.
- Set the baseUrl to the address that is actually reachable in CI.
- run: |
until curl -sf http://localhost:8080/health; do sleep 2; done
- run: ./mvnw gatling:test -DbaseUrl=http://localhost:8080Set baseUrl from the reachable address
Pass the correct host and port into the simulation so it targets what CI publishes.
val httpProtocol = http.baseUrl(System.getProperty("baseUrl", "http://localhost:8080"))How to prevent it
- Wait for the target to be ready before launching Gatling.
- Parameterize baseUrl and pass the reachable CI address.
- Publish the app port the simulation targets in CI.