org.springframework.web.reactive.function.client.WebClient MalformedChunkCodingException: Bad chunk header

989 views Asked by At

I have a spring boot application (2.2.6.RELEASE) which makes call to other Spring boot service through org.springframework.web.reactive.function.client.WebClient which I build in the following manner :

final SslContext sslContext = buildSslContext(keyStorePassword, trustStore, keyStore);

final HttpClient httpClient = HttpClient.create().secure(ssl -> ssl.sslContext(sslContext));

return WebClient.builder().clientConnector(new ReactorClientHttpConnector(httpClient.wiretap(true)))
                .exchangeStrategies(loggingExchangeStrategy()).build();

Normally this works fine. However I when I started performance testing the application using jmeter and bombarding it with requests, I randomly started getting failed responses with the following exception :

org.apache.http.MalformedChunkCodingException: Bad chunk header: {"order":{"status" {"status":"Success"}}}
    at org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:274)
    at org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
    at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:183)
    at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:135)
    at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:148)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.readResponse(HTTPSamplerBase.java:1905)
    at org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl.readResponse(HTTPAbstractImpl.java:476)
    at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:668)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:66)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1281)
    at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1270)
    at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:630)
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558)
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
    at java.lang.Thread.run(Thread.java:748)

I also then got a similar exception while normally testing the application with the following exception :

"org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected\r\n\tat org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:268)\r\n\tat org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:227)\r\n\tat org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:186)\r\n\tat org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:137)\r\n\tat sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)\r\n\tat sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)\r\n\tat sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)\r\n\tat 

Since the exception dont seem to be from my code it seems that the problem is with WebClient. Is it?

  • It seems that it has something to do with Java, MalformedChunkCodingException
  • If this is the case then the issue seems to be the "transfer-encoding" header key with the value "chunked" and the HttpClient. Any idea anyone?
  • Also just for experimenting how can I override and downgrade or upgrade the HttpClient used by WebClient in the pom?
0

There are 0 answers