diff --git a/ktor-client/ktor-client-cio/jvm/test/io/ktor/client/engine/cio/ConnectErrorsTest.kt b/ktor-client/ktor-client-cio/jvm/test/io/ktor/client/engine/cio/ConnectErrorsTest.kt index a401f5703e7..33911cbe0e4 100644 --- a/ktor-client/ktor-client-cio/jvm/test/io/ktor/client/engine/cio/ConnectErrorsTest.kt +++ b/ktor-client/ktor-client-cio/jvm/test/io/ktor/client/engine/cio/ConnectErrorsTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.client.engine.cio @@ -18,7 +18,6 @@ import io.ktor.server.engine.* import io.ktor.server.netty.* import io.ktor.server.response.* import io.ktor.server.routing.* -import io.ktor.utils.io.* import kotlinx.coroutines.* import kotlinx.coroutines.debug.junit5.* import org.junit.jupiter.api.extension.* @@ -102,7 +101,8 @@ class ConnectErrorsTest { } client.getInputStream().readBytes() } - } catch (_: Exception) { } + } catch (_: Exception) { + } } assertEquals("OK", client.get("http://localhost:${serverSocket.localPort}/").body()) thread.join() diff --git a/ktor-client/ktor-client-plugins/ktor-client-websockets/common/test/io/ktor/client/tests/plugins/WebSocketTest.kt b/ktor-client/ktor-client-plugins/ktor-client-websockets/common/test/io/ktor/client/tests/plugins/WebSocketTest.kt index fa39d86ba80..2e15d5f5843 100644 --- a/ktor-client/ktor-client-plugins/ktor-client-websockets/common/test/io/ktor/client/tests/plugins/WebSocketTest.kt +++ b/ktor-client/ktor-client-plugins/ktor-client-websockets/common/test/io/ktor/client/tests/plugins/WebSocketTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.client.tests.plugins @@ -34,7 +34,8 @@ class WebSocketTest { path = "/websocket" ) { } - } catch (_: Throwable) {} + } catch (_: Throwable) { + } assertEquals(443, port) } diff --git a/ktor-server/ktor-server-cio/jvmAndPosix/src/io/ktor/server/cio/backend/ServerPipeline.kt b/ktor-server/ktor-server-cio/jvmAndPosix/src/io/ktor/server/cio/backend/ServerPipeline.kt index 678d9dabd11..7ab47ceed65 100644 --- a/ktor-server/ktor-server-cio/jvmAndPosix/src/io/ktor/server/cio/backend/ServerPipeline.kt +++ b/ktor-server/ktor-server-cio/jvmAndPosix/src/io/ktor/server/cio/backend/ServerPipeline.kt @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + * Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. */ package io.ktor.server.cio.backend @@ -12,11 +12,10 @@ import io.ktor.util.cio.* import io.ktor.utils.io.* import io.ktor.utils.io.charsets.* import io.ktor.utils.io.core.* -import io.ktor.utils.io.errors.* import kotlinx.coroutines.* import kotlinx.coroutines.CancellationException import kotlinx.coroutines.channels.* -import kotlinx.io.IOException +import kotlinx.io.* import kotlin.time.* /** @@ -64,7 +63,8 @@ public fun CoroutineScope.startServerConnectionPipeline( throw io } catch (cancelled: CancellationException) { throw cancelled - } catch (parseFailed: Throwable) { // try to write 400 Bad Request + } catch (parseFailed: Throwable) { + // try to write 400 Bad Request respondBadRequest(actorChannel) break // end pipeline loop } @@ -176,7 +176,8 @@ public fun CoroutineScope.startServerConnectionPipeline( if (isLastHttpRequest(version, connectionOptions)) break } - } catch (cause: IOException) { // already handled + } catch (cause: IOException) { + // already handled coroutineContext.cancel() } finally { actorChannel.close() diff --git a/ktor-server/ktor-server-test-base/jsAndWasmShared/src/io/ktor/server/test/base/EngineTestBase.jsAndWasmShared.kt b/ktor-server/ktor-server-test-base/jsAndWasmShared/src/io/ktor/server/test/base/EngineTestBase.jsAndWasmShared.kt index e3f1e9140ad..c688ed37db0 100644 --- a/ktor-server/ktor-server-test-base/jsAndWasmShared/src/io/ktor/server/test/base/EngineTestBase.jsAndWasmShared.kt +++ b/ktor-server/ktor-server-test-base/jsAndWasmShared/src/io/ktor/server/test/base/EngineTestBase.jsAndWasmShared.kt @@ -110,7 +110,7 @@ actual constructor( starting.join() @OptIn(ExperimentalCoroutinesApi::class) starting.getCompletionExceptionOrNull()?.let { listOf(it) } ?: emptyList() - } catch (t: Throwable) { // InterruptedException? + } catch (t: Throwable) { starting.cancel() listOf(t) } diff --git a/ktor-server/ktor-server-test-base/jvm/src/io/ktor/server/test/base/EngineTestBaseJvm.kt b/ktor-server/ktor-server-test-base/jvm/src/io/ktor/server/test/base/EngineTestBaseJvm.kt index 9d14a47bbd4..86aef1f6bca 100644 --- a/ktor-server/ktor-server-test-base/jvm/src/io/ktor/server/test/base/EngineTestBaseJvm.kt +++ b/ktor-server/ktor-server-test-base/jvm/src/io/ktor/server/test/base/EngineTestBaseJvm.kt @@ -216,7 +216,7 @@ actual abstract class EngineTestBase< starting.join() @OptIn(ExperimentalCoroutinesApi::class) starting.getCompletionExceptionOrNull()?.let { listOf(it) } ?: emptyList() - } catch (t: Throwable) { // InterruptedException? + } catch (t: Throwable) { starting.cancel() listOf(t) } diff --git a/ktor-server/ktor-server-test-base/posix/src/io/ktor/server/test/base/EngineTestBaseNix.kt b/ktor-server/ktor-server-test-base/posix/src/io/ktor/server/test/base/EngineTestBaseNix.kt index a2323d849fa..6e8967fe3ce 100644 --- a/ktor-server/ktor-server-test-base/posix/src/io/ktor/server/test/base/EngineTestBaseNix.kt +++ b/ktor-server/ktor-server-test-base/posix/src/io/ktor/server/test/base/EngineTestBaseNix.kt @@ -121,7 +121,7 @@ actual constructor( starting.join() @OptIn(ExperimentalCoroutinesApi::class) starting.getCompletionExceptionOrNull()?.let { listOf(it) } ?: emptyList() - } catch (t: Throwable) { // InterruptedException? + } catch (t: Throwable) { starting.cancel() listOf(t) }