Hi, I have a bit of an issue with KMP and Websocke...
# multiplatform
b
Hi, I have a bit of an issue with KMP and Websockets. For iOS Im using Darwin engine. Sometime the socket will receive a message which is too big resulting in the exception:
Copy code
2024-10-10 12:20:14.411248+0200 iosApp[61628:2527765] [] nw_protocol_copy_ws_definition_block_invoke [C2.1.1.1:5] input message size 1064960 exceeds maximum message size 1048576
2024-10-10 12:20:14.411709+0200 iosApp[61628:2527765] [connection] nw_read_request_report [C2] Receive failed with error "Message too long"
2024-10-10 12:20:14.412074+0200 iosApp[61628:2527765] Connection 2: received failure notification
2024-10-10 12:20:14.412085+0200 iosApp[61628:2527230] [websocket] Read completed with an error Message too long
2024-10-10 12:20:14.412327+0200 iosApp[61628:2527231] [connection] nw_flow_add_write_request [C2 123:123:123:443 failed parent-flow (satisfied (Path is satisfied), interface: en7, proxy)] cannot accept write requests
2024-10-10 12:20:14.412439+0200 iosApp[61628:2527231] [connection] nw_write_request_report [C2] Send failed with error "Socket is not connected"
2024-10-10 12:20:14.412466+0200 iosApp[61628:2527230] Task <A02BB606-1F2C-401F-B649-D20C47204FAD>.<2> finished with error [40] Error Domain=NSPOSIXErrorDomain Code=40 "Message too long" UserInfo={NSDescription=Message too long, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalWebSocketTask <A02BB606-1F2C-401F-B649-D20C47204FAD>.<2>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalWebSocketTask <A02BB606-1F2C-401F-B649-D20C47204FAD>.<2>}
This is the setup im using:
Copy code
internal actual fun getHttpEngine(): HttpClientEngineFactory<*> =
    Darwin.config {
        configureRequest {
            setTimeoutInterval(60.0)
            nw_ws_options_set_maximum_message_size(
                nw_ws_create_options(nw_ws_version_13),
                (20 * 1024 * 1024).toULong(),
            )
        }
        configureSession {
            setTimeoutIntervalForRequest(60.0) // 60 s == default
            setTimeoutIntervalForResource(604800.0) // 7 days == default
            nw_ws_options_set_maximum_message_size(
                nw_ws_create_options(nw_ws_version_13),
                (20 * 1024 * 1024).toULong(),
            )
        }
    }
I have no idea why Im still getting this error since the maximum message size is set to much larger number than actual message size which I recieve. Does anyone have a solution to this or knows what am I doing wrong? I’ve also set this in the HttpClient:
Copy code
install(WebSockets) {
    maxFrameSize = Long.MAX_VALUE
}
but it doesnt help
c
See first item in the 3.0 release notes😉 https://github.com/ktorio/ktor/releases/tag/3.0.0