Skip to content

Commit

Permalink
KTOR-8135 Socket accept not throwing error on socket close on native
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Vos committed Jan 31, 2025
1 parent 55106bc commit cddc1b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,20 @@ class TCPSocketTest {
serverConnection.close()
server.close()
}

@Test
fun testAcceptErrorOnSocketClose() = testSockets { selector ->
val socket = aSocket(selector)
.tcp()
.bind(InetSocketAddress("127.0.0.1", 0))

launch {
assertFailsWith<IOException> {
socket.accept()
}
}
delay(100) // Make sure socket is awaiting connection using ACCEPT

socket.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ internal actual class SelectorHelper {
for (event in watchSet) {
if (event.descriptor in closeSet) {
completed.add(event)
event.fail(IOException("Selectable closed"))
continue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.ktor.utils.io.*
import io.ktor.utils.io.errors.*
import kotlinx.cinterop.*
import kotlinx.coroutines.*
import kotlinx.io.IOException
import platform.posix.*
import kotlin.coroutines.cancellation.CancellationException

Expand Down Expand Up @@ -152,6 +153,7 @@ internal actual class SelectorHelper {
watchSet.forEach { event ->
if (event.descriptor in closeSet) {
completed.add(event)
event.fail(IOException("Selectable closed"))
return@forEach
}
val wsaEvent = wsaEvents.getValue(event.descriptor)
Expand Down

0 comments on commit cddc1b7

Please sign in to comment.