Okhttp: EOFException handling permessage-deflate response with OkHttp4.5 Websocket

Created on 20 Apr 2020  Â·  10Comments  Â·  Source: square/okhttp

Hello.
I use latest version of OKHttp4.5 and send websocket request with permessage-deflate header which is a compression protocol. But sometime reponse message data is parsed wrong, may be the response message data (original is 140K) is too large. the system error log as follows. Bofore Version of 4.5, everything is ok. I doubt this version is not stable for permessage-deflate protocol.

2020-04-20 18:15:53.144 32664-32689/com. W/System.err: java.io.EOFException: source exhausted prematurely
2020-04-20 18:15:53.144 32664-32689/com. W/System.err:     at okio.InflaterSource.read(InflaterSource.kt:75)
2020-04-20 18:15:53.144 32664-32689/com. W/System.err:     at okhttp3.internal.ws.MessageInflater.inflate(MessageInflater.kt:58)
2020-04-20 18:15:53.144 32664-32689/com. W/System.err:     at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.kt:241)
2020-04-20 18:15:53.144 32664-32689/com. W/System.err:     at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:106)
2020-04-20 18:15:53.144 32664-32689/com. W/System.err:     at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:293)
2020-04-20 18:15:53.144 32664-32689/com. W/System.err:     at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:195)
2020-04-20 18:15:53.144 32664-32689/com. W/System.err:     at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:504)
2020-04-20 18:15:53.144 32664-32689/com. W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
2020-04-20 18:15:53.144 32664-32689/com. W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
2020-04-20 18:15:53.144 32664-32689/com. W/System.err:     at java.lang.Thread.run(Thread.java:761)
bug needs info websockets

All 10 comments

Do you have any information like the server you are connecting to?

@yschimke This is a simple and normal websocket server using Netty. It's good for web brower, not for version of OkHttp4.5.

@swankjesse Yes. I just debug OkHttp testcase, when response message data speed is fast will occur this error. Our server is websocket application which is providing data subscription, so message updates very frequently.

I reproduced this. It’s OkHttp’s fault and I’d like to make a fix shortly.

What’s happening is we’re attempting to decompress bytes using the InflaterSource API from Okio. The Source.read() contract is “returns -1L for EOF, or the positive number of bytes read”. Unfortunately for deflated messages we have neither!

There’s an unsatisfying local fix where we catch the EOFException. The alternative is adding a method to InflaterSource where read() can consume data from the underlying stream but produce no data to the caller.

Is the empty message a form of keepalive?

I think typically it’s an artifact of SYNC_FLUSH.

@yschimke we have not empty message

I think typically it’s an artifact of SYNC_FLUSH.
@swankjesse i agree this, if data update too fast, it may conflict with flush operation.

Was this page helpful?
0 / 5 - 0 ratings