java.io.EOFException is thrown from Flow.collect when trying to send a Ping
See original GitHub issueKtor Version and Engine Used (client or server and name) Ktor 1.3.2 client, ktor-client-okhttp (on top of ktor-client-core and ktor-client-websockets)
Describe the bug
java.io.EOFException
is thrown from Flow.collect
when trying to send
a Ping
message
To Reproduce
- client.wss with a block like this:
{
incoming.consumeAsFlow()
.collect { frame ->
if (frame.isHello) {
GlobalScope.launch {
delay(500L)
send(Frame.Ping(ByteArray(0)))
}
} else {
// Normal frame processing here.
}
}
}
Expected behavior Ping is sent, server responds with Pong.
It’s entirely possible I’m doing something wrong but I can’t see what. This is reproducible 100% of the time. Stacktrace:
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
java.io.EOFException: no more data available - expected end ...
in my use case reason for occurrence of above error was jabber server(ejabberd) was dropping connection after a fixed time interval ofcause when...
Read more >Exceptions in Kotlin Flows - Roman Elizarov - Medium
This implementation collects values from the upstream flow it is called on and emits them downstream, wrapping the collect call into the try...
Read more >Binder - Android Developers
Return the ID of the process that sent you the current transaction that is being processed. static final int, getCallingUid().
Read more >Fix list for IBM WebSphere Application Server traditional V9
Migration, PH36102, MIGR0285E: An unexpected internal error occurred with exception java.io.eofException: unexpected end of zlib input stream error.
Read more >JBoss EAP 7.3.0.Beta Model Reference
createConnector should never throw an exception, implementation is badly behaved, ... AMQ224035, ERROR, Failed to close cluster connection flow record.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @edenman, well the only thing I can recommend you is to try CIO out. Is does support manual Ping/Pong processing using RawWebSockets.
And just to fix the status, speaking about OkHttp I see here several inconveniences. Firstly, when we send a frame we don’t get an exception immediately. Send operation is performed asynchronously and we are able to get an exception only when try to send something again. Secondly, OkHttp provides it’s own Ping/Pong mechanism which is not properly integrated with Ktor infrastructure so far.
I can nothing to suggest you but try CIO, so I’ll close the issue. If you have any ideas or suggestions feel free to reopen it.
I was experiencing the
java.io.EOFException
error too and suspected it could be related to pinging while collecting a flow for an extended period of time. Switching to the CIO engine from the OkHttp engine fixed the issue, thanks!