question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.io.EOFException is thrown from Flow.collect when trying to send a Ping

See original GitHub issue

Ktor 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

  1. 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:

Screen Shot 2020-04-18 at 1 52 39 PM

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dmitrievanthonycommented, Apr 22, 2020

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.

0reactions
techygrrrlcommented, Jul 16, 2022

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.

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found