From 7237553103b9b3db4417c9955c8cfd6ea15ec8d3 Mon Sep 17 00:00:00 2001 From: Piasy Date: Tue, 15 Jul 2025 22:14:41 +0800 Subject: [PATCH 1/3] update ktor (fix linux curl engine issue) --- gradle/libs.versions.toml | 2 +- .../socketio/engineio/transports/transport.kt | 18 ++---------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7bdf9da..1515b3b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,7 +7,7 @@ targetSdk = "35" agp = "8.7.3" kotlin = "2.1.10" mockk = "1.13.16" -ktor = "3.1.0" +ktor = "3.2.2" coroutine = "1.10.1" compose = "1.7.8" diff --git a/kmp-socketio/src/commonMain/kotlin/com/piasy/kmp/socketio/engineio/transports/transport.kt b/kmp-socketio/src/commonMain/kotlin/com/piasy/kmp/socketio/engineio/transports/transport.kt index c117bb5..8ad652b 100644 --- a/kmp-socketio/src/commonMain/kotlin/com/piasy/kmp/socketio/engineio/transports/transport.kt +++ b/kmp-socketio/src/commonMain/kotlin/com/piasy/kmp/socketio/engineio/transports/transport.kt @@ -79,22 +79,8 @@ class DefaultHttpClientFactory( } // Linux curl engine doesn't work for simultaneous websocket and http request. // see https://youtrack.jetbrains.com/issue/KTOR-8259/ - // Use two http client could work around it. - private val httpClient: HttpClient = if (!Platform.isLinux) wsClient else httpClient( - trustAllCerts = trustAllCerts, - ) { - install(Logging) { - logger = object : Logger { - override fun log(message: String) { - com.piasy.kmp.xlog.Logging.info("Net", message) - } - } - level = LogLevel.ALL - } - install(WebSockets) { - pingIntervalMillis = 20_000 - } - } + // But it's fixed in 3.2.0. + private val httpClient: HttpClient = wsClient override suspend fun createWs( url: String, From a63d6a05f625c61fd4d3225d51f2614d875dd674 Mon Sep 17 00:00:00 2001 From: Piasy Date: Tue, 15 Jul 2025 22:26:03 +0800 Subject: [PATCH 2/3] update test case --- .../kmp/socketio/socketio/ConnectionTestLinux.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kmp-socketio/src/linuxTest/kotlin/com/piasy/kmp/socketio/socketio/ConnectionTestLinux.kt b/kmp-socketio/src/linuxTest/kotlin/com/piasy/kmp/socketio/socketio/ConnectionTestLinux.kt index 43eaf88..e0ff925 100644 --- a/kmp-socketio/src/linuxTest/kotlin/com/piasy/kmp/socketio/socketio/ConnectionTestLinux.kt +++ b/kmp-socketio/src/linuxTest/kotlin/com/piasy/kmp/socketio/socketio/ConnectionTestLinux.kt @@ -92,7 +92,7 @@ class ConnectionTestLinux : ConnectionTest() { } @Test - fun `simultaneous ws and http request with a single http client will hang`() = doTest { + fun `simultaneous ws and http request with a single http client will also work`() = doTest { val config: HttpClientConfig<*>.() -> Unit = { install(io.ktor.client.plugins.logging.Logging) { logger = object : Logger { @@ -110,7 +110,9 @@ class ConnectionTestLinux : ConnectionTest() { config(this) } - assertFailsWith { + var pollRes = "" + // ktor 3.2.0 fix the problem + //assertFailsWith { withContext(Dispatchers.Default) { withTimeout(5000) { client.webSocket("ws://localhost:3000/socket.io/?EIO=4&transport=websocket", {}) { @@ -126,8 +128,8 @@ class ConnectionTestLinux : ConnectionTest() { } Logging.info(TAG, "http response status: ${resp.status}") if (resp.status.isSuccess()) { - val body = resp.bodyAsText() - Logging.info(TAG, "http response body: $body") + pollRes = resp.bodyAsText() + Logging.info(TAG, "http response body: $pollRes") break } } catch (e: Exception) { @@ -138,6 +140,9 @@ class ConnectionTestLinux : ConnectionTest() { } } } - } + //} + + val pkt = EngineIO.decodeHttpBatch(pollRes, SocketIO::decode)[0] + assertTrue(pkt is EngineIOPacket.Open) } } From 33638faf3918db9f5ef41b4f7d9352f31fb77e59 Mon Sep 17 00:00:00 2001 From: Piasy Date: Wed, 16 Jul 2025 08:34:06 +0800 Subject: [PATCH 3/3] update version code --- buildSrc/src/main/kotlin/Constants.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/Constants.kt b/buildSrc/src/main/kotlin/Constants.kt index 370ef17..4b395bf 100644 --- a/buildSrc/src/main/kotlin/Constants.kt +++ b/buildSrc/src/main/kotlin/Constants.kt @@ -1,7 +1,7 @@ object Consts { const val releaseGroup = "com.piasy" const val releaseName = "kmp-socketio" - const val releaseVersion = "1.3.0" + const val releaseVersion = "1.3.1" val androidNS = "$releaseGroup.${releaseName.replace('-', '.')}" }