WebSocket throws a vague IOException when internet is disconnected
See original GitHub issueKtor Version
1.2.0-rc
Ktor Engine Used(client or server and name)
Client/CIO
JVM Version, Operating System and Relevant Context
OpenJDK 11.0.3, Arch Linux.
Feedback
When the internet is disconnected, a vague java.io.IOException
is thrown twice, and it cannot be caught.
Exception in thread "pool-2-thread-3" java.io.IOException: Connection reset by peer
at java.base/sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at java.base/sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276)
at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:233)
at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:223)
at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:358)
at kotlinx.io.nio.ChannelsKt.read(Channels.kt:117)
at io.ktor.network.sockets.CIOReaderKt$attachForReadingDirectImpl$1$1.invokeSuspend(CIOReader.kt:75)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.ResumeModeKt.resumeMode(ResumeMode.kt:67)
at kotlinx.coroutines.DispatchedKt.resume(Dispatched.kt:309)
at kotlinx.coroutines.DispatchedKt.resumeUnconfined(Dispatched.kt:49)
at kotlinx.coroutines.DispatchedKt.dispatch(Dispatched.kt:295)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:250)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:260)
at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:189)
at io.ktor.network.selector.SelectorManagerSupport.handleSelectedKey(SelectorManagerSupport.kt:83)
at io.ktor.network.selector.SelectorManagerSupport.handleSelectedKeys(SelectorManagerSupport.kt:63)
at io.ktor.network.selector.ActorSelectorManager.process(ActorSelectorManager.kt:74)
at io.ktor.network.selector.ActorSelectorManager$process$1.invokeSuspend(ActorSelectorManager.kt)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Websockets - onclose - server/client - internet connection ...
I found a solution/workaround for this. Once your internet connection goes down, socket channel remain intact, and client can no more send ...
Read more >Disable system out for dropped connections : KTOR-753
KTOR-623 WebSocket throws a vague IOException when internet is disconnected ... IOException: Connection reset by peer at sun.nio.ch.
Read more >Troubleshooting connection issues
You are trying to reach a plain WebSocket server; The server is not reachable; The client is not compatible with the version of...
Read more >Fix list for IBM WebSphere Application Server V8.5
PI81124, Closing websocket session will throw NullPointerException ... the response from the app server does not indicate ESI caching and client disconnects.
Read more >A Guide to the Java API for WebSocket
WebSocket provides an alternative to the limitation of efficient ... session) throws IOException { // Get session and WebSocket connection } ...
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
Is this exception supposed to be thrown when the internet is disconnected? I am seeing this exception on a benchmarking test when attempting to make 100,000 concurrent requests.
https://github.com/brendanw/profilehttp
Are clients expected to handle this error? It would be great to see some guidance from the ktor team.
This is not limited to websockets, nor is it limited to a network link disruption. I have this situation for a straight persistent HTTP CIO connection, and it happens when the remote server disconnects the socket. The exception output is distracting and unnecessary, as there is nothing the client code can do about it.
I am using ktor 1.2.1.