Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exceptions ignored in select code #4681

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Thomas-Vos
Copy link
Contributor

Properly pass exceptions so they can be detected when using the sockets. Maybe this will also help find any remaining issues in the selection code.

@Thomas-Vos Thomas-Vos marked this pull request as draft February 18, 2025 02:18
@Thomas-Vos Thomas-Vos marked this pull request as ready for review February 18, 2025 14:27
@Thomas-Vos
Copy link
Contributor Author

Thomas-Vos commented Feb 18, 2025

The actual stack trace that is thrown in the test on Native unfortunately only points to internal Ktor code (on JVM it is better, but not Android). In the past the Ktor code was changed to catch and ignore these exceptions, https://youtrack.jetbrains.com/issue/KTOR-2914/java.lang.IllegalArgumentException-Failed-requirement.-in-SelectorManagerSupport. I don't know if something changed so they can be caught now, or if that was always possible already, and the stack trace doesn't help with this. There is no way to know where in the app it crashes. I feel like no longer ignoring exceptions will cause issues again, but ignoring isn't a good solution. What to do about this?

kotlinx.io.IOException: Selector closed.
	at kotlin.Throwable#<init>(/opt/buildAgent/work/b5c630f73501b353/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:30)
	at kotlin.Exception#<init>(/opt/buildAgent/work/b5c630f73501b353/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23)
	at kotlinx.io.IOException#<init>(/opt/buildAgent/work/22e3a7db6b861ba7/core/native/src/-NonJvmPlatform.kt:26)
	at io.ktor.network.selector.WorkerSelectorManager#select#suspend(/Users/thomas/GitHub/ktor/ktor-network/posix/src/io/ktor/network/selector/WorkerSelectorManager.kt:35)
	at io.ktor.network.selector.SelectorManager#select#suspend(/Users/thomas/GitHub/ktor/ktor-network/posix/src/io/ktor/network/selector/SelectorManager.kt:35)
	at io.ktor.network.sockets.DatagramSocketNative.$readDatagramCOROUTINE$0.invokeSuspend#internal(/Users/thomas/GitHub/ktor/ktor-network/posix/src/io/ktor/network/sockets/DatagramSocketNative.kt:66)
	at io.ktor.network.sockets.DatagramSocketNative.readDatagram#internal(/Users/thomas/GitHub/ktor/ktor-network/posix/src/io/ktor/network/sockets/DatagramSocketNative.kt:62)
	at io.ktor.network.sockets.DatagramSocketNative.$<init>$lambda$0COROUTINE$1.invokeSuspend#internal(/Users/thomas/GitHub/ktor/ktor-network/posix/src/io/ktor/network/sockets/DatagramSocketNative.kt:43)
	at io.ktor.network.sockets.DatagramSocketNative.<init>$lambda$0#internal(/Users/thomas/GitHub/ktor/ktor-network/posix/src/io/ktor/network/sockets/DatagramSocketNative.kt:40)
	at io.ktor.network.sockets.DatagramSocketNative.$<init>$lambda$0$FUNCTION_REFERENCE$0.invoke#internal(/Users/thomas/GitHub/ktor/ktor-network/posix/src/io/ktor/network/sockets/DatagramSocketNative.kt:40)
	at kotlin.Function2#invoke(/Users/teamcity/.gradle/daemon/8.9/[K][Suspend]Functions:1)
	at kotlin.coroutines.intrinsics.object-4.invokeSuspend#internal(/opt/buildAgent/work/b5c630f73501b353/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/intrinsics/IntrinsicsNative.kt:254)
	at kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(/opt/buildAgent/work/b5c630f73501b353/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:50)
	at kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(/opt/buildAgent/work/b5c630f73501b353/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:30)
	at kotlin.coroutines.Continuation#resumeWith(/opt/buildAgent/work/b5c630f73501b353/kotlin/libraries/stdlib/src/kotlin/coroutines/Continuation.kt:26)
	at kotlinx.coroutines.DispatchedTask#run(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:100)
	at kotlinx.coroutines.Runnable#run(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Runnable.kt:12)
	at kotlinx.coroutines.internal.LimitedDispatcher.Worker.run#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/LimitedDispatcher.kt:113)
	at kotlinx.coroutines.Runnable#run(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Runnable.kt:12)
	at kotlinx.coroutines.MultiWorkerDispatcher.$workerRunLoop$lambda$2COROUTINE$0.invokeSuspend#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/MultithreadedDispatchers.kt:110)
	at kotlinx.coroutines.MultiWorkerDispatcher.workerRunLoop$lambda$2#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/MultithreadedDispatchers.kt:102)
	at kotlinx.coroutines.MultiWorkerDispatcher.$workerRunLoop$lambda$2$FUNCTION_REFERENCE$4.invoke#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/MultithreadedDispatchers.kt:102)
	at kotlin.Function2#invoke(/Users/teamcity/.gradle/daemon/8.9/[K][Suspend]Functions:1)
	at kotlin.coroutines.intrinsics.object-4.invokeSuspend#internal(/opt/buildAgent/work/b5c630f73501b353/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/intrinsics/IntrinsicsNative.kt:254)
	at kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(/opt/buildAgent/work/b5c630f73501b353/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:50)
	at kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(/opt/buildAgent/work/b5c630f73501b353/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:30)
	at kotlin.coroutines.Continuation#resumeWith(/opt/buildAgent/work/b5c630f73501b353/kotlin/libraries/stdlib/src/kotlin/coroutines/Continuation.kt:26)
	at kotlinx.coroutines.DispatchedTask#run(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:100)
	at kotlinx.coroutines.Runnable#run(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Runnable.kt:12)
	at kotlinx.coroutines.EventLoopImplBase#processNextEvent(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/EventLoop.common.kt:263)
	at kotlinx.coroutines.EventLoop#processNextEvent(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/EventLoop.common.kt:49)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:130)
	at kotlinx.coroutines#runBlocking(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:69)
	at kotlinx.coroutines#runBlocking$default(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:45)
	at kotlinx.coroutines.MultiWorkerDispatcher.workerRunLoop#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/MultithreadedDispatchers.kt:102)
	at kotlinx.coroutines.MultiWorkerDispatcher.<init>$lambda$1$lambda$0#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/MultithreadedDispatchers.kt:86)
	at kotlinx.coroutines.MultiWorkerDispatcher.$<init>$lambda$1$lambda$0$FUNCTION_REFERENCE$6.invoke#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/MultithreadedDispatchers.kt:86)
	at kotlinx.coroutines.MultiWorkerDispatcher.$<init>$lambda$1$lambda$0$FUNCTION_REFERENCE$6.$<bridge-DNN>invoke(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/MultithreadedDispatchers.kt:86)
	at kotlin.Function0#invoke(/Users/teamcity/.gradle/daemon/8.9/[K][Suspend]Functions:1)
	at <global>.WorkerLaunchpad(/opt/buildAgent/work/b5c630f73501b353/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:95)
	at <global>._ZN6Worker19processQueueElementEb(Unknown Source)
	at <global>._ZN12_GLOBAL__N_113workerRoutineEPv(Unknown Source)
	at <global>._pthread_start(Unknown Source)
	at <global>.thread_start(Unknown Source)

Also it seems that after failure calling awaitClosed will throw CancellationException, is that expected? See for example io.ktor.network.sockets.tests.UDPSocketTest.testBroadcastSuccessful[mingwX64] at https://ktor.teamcity.com/buildConfiguration/Ktor_KtorCore_All/321802

@Thomas-Vos Thomas-Vos marked this pull request as draft February 18, 2025 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant