livekit / client-sdk-android

LiveKit SDK for Android
https://docs.livekit.io
Apache License 2.0
160 stars 63 forks source link

GRPC Data Unmarshalling Error #396

Open aliumujib opened 3 months ago

aliumujib commented 3 months ago

Describe the bug

We're using Livekit in our Android app, calling works well and we're able to create and join rooms. However trying to use the room.localParticipant.publishData mechanism doesn't work. When trying to send the data from the client, it throws the following error which crashes our app:

Screenshot 2024-03-25 at 10 54 04

We also tried moving the publishData call to our backend server, but the app still crashes when the SDK tries to deserialize data received, so RoomEvent.DataReceived is never triggered.

To Reproduce Steps to reproduce the behavior:

  1. Connect to a call with mutliple devices

  2. Try to send some data through the room.localParticipant.publishData function. In our case, we're trying to publish a small JSON payload that has been serialized to bytes.

    {
    "type": "com.reachout.android.calls.ui.base.CallEventSignal.RequestToSpeak",
    "requesterId": "NTuScSP1S9K8hRS45EhqgQ=="
    }
  3. The app crashes with the exception in the screenshot above.

Expected behavior The data should be broadcast to all the participants in the room and be available for deserialization via the RoomEvent.DataReceived event.

Device Info:

Additional context We use GRPC for all network calls in all the app, the we use the following library versions:

versions.grpc = "1.62.2"

def grpc = [:]
grpc.grpc_okhttp = "$groups.grpc:grpc-okhttp:$versions.grpc"
grpc.grpc_stub = "$groups.grpc:grpc-stub:$versions.grpc"
grpc.grpc_protobuff_lite = "$groups.grpc:grpc-protobuf-lite:1.62.2"
grpc.grpc_kotlin_stub = "$groups.grpc:grpc-kotlin-stub:1.4.1"
grpc.grpc_protobuff_kt_lite = "com.google.protobuf:protobuf-kotlin-lite:4.26.0"
deps.grpc = grpc

Protobuff setup:

protobuf {
    protoc {
        if (project.hasProperty('protoc_platform')) {
            artifact = "com.google.protobuf:protoc:21.0-rc-1:${protoc_platform}"
        } else {
            artifact = "com.google.protobuf:protoc:21.0-rc-1"
        }
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.62.2' // CURRENT_GRPC_VERSION
        }
        grpckt {
            artifact = "io.grpc:protoc-gen-grpc-kotlin:1.4.1:jdk8@jar"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                kotlin { option 'lite' }
                java { option 'lite' }
            }
            task.plugins {
                grpc { // Options added to --grpc_out
                    option 'lite'
                }
                grpckt { // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}
davidliu commented 3 months ago

The error in the screenshot looks like that's when you receive a message from the server. Do you also have one from when you send? Also text error logs would be appreciated instead of screenshots.

aliumujib commented 3 months ago

Thanks for your response @davidliu It is exactly the same error both ways. Please see the logs below:

java.lang.StringIndexOutOfBoundsException: length=23; index=23
    at java.lang.String.charAt(Native Method)
    at com.google.protobuf.MessageSchema.newSchemaForRawMessageInfo(MessageSchema.java:427)
    at com.google.protobuf.MessageSchema.newSchema(MessageSchema.java:221)
    at com.google.protobuf.ManifestSchemaFactory.newSchema(ManifestSchemaFactory.java:85)
    at com.google.protobuf.ManifestSchemaFactory.createSchema(ManifestSchemaFactory.java:71)
    at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:93)
    at com.google.protobuf.MessageSchema.getMessageFieldSchema(MessageSchema.java:4849)
    at com.google.protobuf.MessageSchema.mergeFromHelper(MessageSchema.java:4241)
    at com.google.protobuf.MessageSchema.mergeFrom(MessageSchema.java:3846)
    at com.google.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1531)
    at com.google.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1630)
    at com.google.protobuf.GeneratedMessageLite.parseFrom(GeneratedMessageLite.java:1619)
    at com.google.protobuf.GeneratedMessageLite.parseFrom(GeneratedMessageLite.java:1612)
    at livekit.LivekitModels$DataPacket.parseFrom(LivekitModels.java:9997)
    at io.livekit.android.room.RTCEngine.onMessage(RTCEngine.kt:941)
    at io.livekit.android.room.RTCEngine$DataChannelObserver.onMessage(RTCEngine.kt:969)
#
# Fatal error in: gen/jni_headers/sdk/android/generated_metrics_jni/../../../../../../../../../../../_source/android_prefixed/webrtc/src/sdk/android/src/jni/jni_generator_helper.h, line 95
# last system error: 0
# Check failed: !env->ExceptionCheck()
# 
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 10647 (signaling_threa), pid 10366 (eachout.android)
Cmdline: chat.reachout.android
pid: 10366, tid: 10647, name: signaling_threa  >>> chat.reachout.android <<<
    #01 pc 000000000042086c  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #02 pc 0000000000420eb0  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #03 pc 000000000041019c  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #04 pc 00000000004100ac  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #05 pc 00000000008117e4  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #06 pc 000000000043e014  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #07 pc 000000000043d454  /data/app/~~v
aliumujib commented 3 months ago

Also we suspect that the error is due to the optional field in this message (we're using GRPC kotlin). I can't find usages of optional fields anywhere else in the models.proto file which might explain why other pieces of functionality works.

aliumujib commented 3 months ago

@davidliu following up.

davidliu commented 2 months ago

Hey, sorry for the delay.

I wonder if it's a compatibility issue here? We're on 3.22.0, and you're using 4.26.0 here. A bump in major version might be the cause here.

GRPC itself seems to not have upgraded to 4.26 either, as noted in https://github.com/grpc/grpc-java/issues/11015

Can you try downgrading to 3.22 (or 3.25.1, which is what grpc uses)?