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.

socket.isClosed remains `false` after socket.close() call

See original GitHub issue

Hi, I’m using io.ktor:ktor-network-tls:1.0.1[1], running JDK8 on MacOSX 10.10.5 The minimal working example to reproduce the problem is as follows:

import io.ktor.network.selector.ActorSelectorManager
import io.ktor.network.sockets.aSocket
import io.ktor.network.sockets.isClosed
import io.ktor.network.sockets.openReadChannel
import io.ktor.network.sockets.openWriteChannel
import kotlinx.coroutines.Dispatchers.Unconfined
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.runBlocking

/** Created by revin(caoyunbin@baidu.com) on 2018-12-26. */
fun main(args:Array<String>)=runBlocking(Unconfined){
    val tcp=aSocket(ActorSelectorManager(newSingleThreadContext("httpIO"))).tcp()
    val socket=tcp.connect("www.baidu.com",80)
    socket.openReadChannel();socket.openWriteChannel()
    socket.close();println(socket.isClosed)
}

The result expected from the above code is true but instead I got false

image

  1. I can’t use io.ktor:ktor-network-tls:1.1.0, which is the latest version as of writing. The following error shows up when trying to build the project. So I’m using an earlier version to report the problem
CONFIGURE FAILED in 7s
Could not find org.jetbrains.kotlinx:atomicfu:0.12.0.
Searched in the following locations:
    https://repo1.maven.org/maven2/org/jetbrains/kotlinx/atomicfu/0.12.0/atomicfu-0.12.0.pom
    https://repo1.maven.org/maven2/org/jetbrains/kotlinx/atomicfu/0.12.0/atomicfu-0.12.0.jar
Required by:
    project :jvm > io.ktor:ktor-network-tls:1.1.0
    project :jvm > io.ktor:ktor-network-tls:1.1.0 > org.jetbrains.kotlinx:kotlinx-io-jvm:0.1.2
    project :jvm > io.ktor:ktor-network-tls:1.1.0 > org.jetbrains.kotlinx:kotlinx-coroutines-io-jvm:0.1.2
    project :jvm > io.ktor:ktor-network-tls:1.1.0 > io.ktor:ktor-network:1.1.0
  1. According to maven(https://mvnrepository.com/artifact/io.ktor/ktor-network-tls/1.1.0), ktor-network-tls relies on ktor-http-cio-native, is that intentional?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
oleg-larshincommented, Aug 10, 2020

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

0reactions
Stexxecommented, Jul 7, 2021

Cannot reproduce with Ktor 1.6.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Socket isClosed() returns false after client disconnected
The system call then returns no error but 0 bytes and this means that there will be no more data from the peer....
Read more >
The program not closed after socket.close() · Issue #85 - GitHub
After pressing 'q' socket call close() but programm still working. I look at debugger and find there EventThread in runnable state.
Read more >
socket bind throws socket closed — oracle-tech
isClosed () what the javadoc should say: Indicates if close() has been called on this socket. Initially this method returns false. After Socket.close()...
Read more >
In Java, what happend to socket on server side (not ... - Quora
Socket.isConnected() is still true and Socket.isClosed() is still false. ... the server will unbind the client but the server connection will not be...
Read more >
no IOException on socket read/write after remote close ...
closed. Once again, the socket's state both before and after the write, is ... thread 1 stays blocked inside the readByte() call and...
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