Hi, I'm getting unexpected end of stream / EOFExce...
# pact-jvm
j
Hi, I'm getting unexpected end of stream / EOFException: \n not found: limit=0 from the consumer mock server. Java (Spring, not Spring Boot) app, pact-jvm consumer + consumer-junit5, client uses OkHttp 4.12.0. Reproduces on 4.7.3 and 4.6.15, with both KTorServer and JavaHttpServer. Not a DNS/localhost issue either — same result pointing the client at a literal 127.0.0.1:<port>. Fails every single run on both JDK 17 and JDK 25 (100% reproducible, even with -Djava.net.preferIPv4Stack=true). Minimal repro:
Copy code
@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "example-provider", pactVersion = PactSpecVersion.V4)
class ExampleClientPactTest {

    private final OkHttpClient client = new OkHttpClient();

    @Pact(consumer = "example-consumer")
    public V4Pact createOrderPact(PactDslWithProvider builder) {
        return builder
            .given("provider accepts an order")
            .uponReceiving("a request to create an order")
            .path("/orders")
            .method("POST")
            .headers(Map.of("Content-Type", "application/json"))
            .body(new PactDslJsonBody()
                .stringType("customerId", "cust-123")
                .decimalType("amount", 100.00))
            .willRespondWith()
            .status(200)
            .headers(Map.of("Content-Type", "application/json"))
            .body(new PactDslJsonBody()
                .stringType("orderId", "order-456")
                .stringValue("status", "CREATED"))
            .toPact(V4Pact.class);
    }

    @Test
    @PactTestFor(pactMethod = "createOrderPact")
    void should_create_order(MockServer mockServer) throws IOException {
        Request request = new Request.Builder()
            .url(mockServer.getUrl() + "/orders")
            .post(RequestBody.create(
                "{\"customerId\":\"cust-123\",\"amount\":100.00}",
                MediaType.get("application/json")))
            .build();

        try (Response response = client.newCall(request).execute()) {
            assertThat(response.code()).isEqualTo(200);
        }
    }
}
Fails with:
java.io.IOException: unexpected end of stream on <http://localhost>:PORT/...
Caused by: java.io.EOFException: \n not found: limit=0 content=…
at okio.RealBufferedSource.readUtf8LineStrict
at okhttp3.internal.http1.HeadersReader.readLine
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders
and Pact reports the interaction as not received (client never got a full response). Looks like a race where the client connects before the mock server is ready to respond. Anyone seen this / know a fix or workaround?
r
I ran your test in the Pact-JVM build, and it runs just fine. Tried both OkHttp 4.12.0 and 5.4.0.
It must be something in your project that is causing it, like an interceptor or maybe some Spring AOP
Here is the test and the build is green: github.com/pact-foundation/pact-jvm/blob/…/OkHttpTest.java