rsocket / rsocket-kotlin

RSocket Kotlin multi-platform implementation
http://rsocket.io
Apache License 2.0
552 stars 37 forks source link

`No encoder for java.lang.Long` error when connecting from Kotlin/JS #155

Closed sureshg closed 3 years ago

sureshg commented 3 years ago

The following sample app compiled using Kotlin/JS(IR) is failing with 513 Application Error.

val client = HttpClient {
    install(WebSockets)
    install(RSocketSupport)
}

 val rSocket = client.rSocket(urlString = "wss://demo.rsocket.io/rsocket")
 val stream = rSocket.requestStream(Payload.Empty)
 stream.take(10).collect { println(it.data.readText()) }

Error

ApplicationError {message: "No encoder for java.lang.Long, current value type is class java.lang.Long", cause: undefined, name: "ApplicationError", _errorCode_0: 513, stack: "ApplicationError: No encoder for java.lang.Long, c…rains_kotlinx_kotlinx_coroutines_core.js:15037:9)"}
cause: undefined
message: "No encoder for java.lang.Long, current value type is class java.lang.Long"
name: "ApplicationError"
_errorCode_0: 513
stack: "ApplicationError: No encoder for java.lang.Long, current value type is class java.lang.Long↵    at RSocketError_0 (webpack-internal:///./kotlin/kotlin_io_rsocket_kotlin_rsocket_core.js:714:17)↵    at readError (webpack-internal:///./kotlin/kotlin_io_rsocket_kotlin_rsocket_core.js:3430:37)↵    at readFrame (webpack-internal:///./kotlin/kotlin_io_rsocket_kotlin_rsocket_core.js:3577:17)↵    at $receiveFrameCOROUTINE$0.doResume_3 (webpack-internal:///./kotlin/kotlin_io_rsocket_kotlin_rsocket_core.js:364:20)↵    at $receiveCOROUTINE$0.CoroutineImpl_0.resumeWith_9 (webpack-internal:///./kotlin/kotlin_kotlin.js:21134:37)↵    at $receiveCOROUTINE$0.CoroutineImpl_0.resumeWith_8 (webpack-internal:///./kotlin/kotlin_kotlin.js:21164:17)↵    at CancellableContinuationImpl.DispatchedTask.run_6 (webpack-internal:///./kotlin/kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.js:12978:24)↵    at WindowMessageQueue.MessageQueue.process_2 (webpack-internal:///./kotlin/kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.js:14817:21)↵    at _no_name_provided__112.invoke_163 (webpack-internal:///./kotlin/kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.js:14963:21)↵    at eval (webpack-internal:///./kotlin/kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.js:15037:9)"
__proto__: RSocketError
  kotlin("js") version "1.5.0-RC"
  ...
  val ktorVersion = "1.5.3"
  implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.4.3")
  implementation("io.ktor:ktor-client-js:$ktorVersion")
  implementation("io.ktor:ktor-client-websockets:$ktorVersion")
  implementation("io.rsocket.kotlin:rsocket-core:0.12.0")
  implementation("io.rsocket.kotlin:rsocket-transport-ktor-client:0.12.0")
whyoleg commented 3 years ago

Can you try to use kotlin 1.4.32? 0.12.0 isn't quite ready for kotlin 1.5. Also, it's more looks like server exception. @yschimke can it be demo server error/bug?

yschimke commented 3 years ago

Yep. I'll test tonight locally.

yschimke commented 3 years ago

Didn't get to this yet. Plan is still to take your repro, apply to https://stackoverflow.com/questions/66397279/how-to-make-a-reproduction-of-a-bug-for-rsocket-kotlin and debug against a local rsocket-demo app (checkout and run http://github.com/rsocket/rsocket-demo in an IDE).

sureshg commented 3 years ago

Thanks for the link, that was really helpful. Debugged locally and the issue was with not setting proper payload MIME types.

It started working after setting application/json as payload MIME type.

val client = HttpClient {
     install(WebSockets)
     install(RSocketSupport) {
        connector = RSocketConnector {
           connectionConfig {
               keepAlive = KeepAlive(interval = Duration.seconds(30), maxLifetime = Duration.minutes(2))
               payloadMimeType = PayloadMimeType(data = "application/json", metadata = "application/json")
      }

- Successful Frames

Frame { "data": "hello world", "dataMimeType": "application/json", "flags": "NO FLAGS (0x0)", "keepAlive": 30000, "length": 63, "lifetime": 120000, "majorVersion": 1, "metadata": null, "metadataMimeType": "application/json", "minorVersion": 0, "resumeToken": null, "streamId": 0, "type": "SETUP (0x1)" } Frame { "data": null, "flags": "NO FLAGS (0x0)", "length": 10, "metadata": null, "requestN": 64, "streamId": 1, "type": "REQUEST_STREAM (0x6)" }

sureshg commented 3 years ago

Sorry for the inconvenience, it is clear on the doc but somehow I missed it.

yschimke commented 3 years ago

Thanks for the report we should improve some of these error messages