Question

Enter code here I've implemented an SSE server and client. The server is implemented using Netty and the client uses Apache http client.

If I send a message at least every 30 seconds it all seems to work fine, but if I do not I will intermittently get this exception:

```
 Caused by: org.apache.http.MalformedChunkCodingException: Chunked stream ended unexpectedly
    W/System.err( 2879):    at org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:222)
    W/System.err( 2879):    at org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:183)
    W/System.err( 2879):    at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:155)
    W/System.err( 2879):    at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:159)
    W/System.err( 2879):    at java.io.InputStreamReader.read(InputStreamReader.java:244)
    W/System.err( 2879):    at java.io.BufferedReader.fillBuf(BufferedReader.java:130)
    W/System.err( 2879):    at java.io.BufferedReader.readLine(BufferedReader.java:354)
    W/System.err( 2879):    at com.clover.engine.push.SSEConnection$1.call(SSEConnection.java:85)
    W/System.err( 2879):    at com.clover.engine.push.SSEConnection$1.call(SSEConnection.java:79)
    W/System.err( 2879):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
```

Right now I'm sending a keep alive message every 30 seconds, but I'd prefer to not have to.

Any suggestions on how to prevent this exception from occurring?

Was it helpful?

Solution

The cause of this exception was actually haproxy which was closing the socket when it was idle for too long.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top