Repository navigation
Conversation
The reliable buffer was only trimmed when the data channel's bufferedAmount flow emitted. That flow is a StateFlow, and small packets leave the channel at once, so the value stays at 0 and never emits again. With room metrics on by default, two reliable packets a second piled up until the room disconnected. Trim with the channel's live bufferedAmount() after every reliable send, as the JS SDK does. The flow collector stays to trim after a drain. Fixes #1063 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 8fd2e12 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| // ByteBuffer just sent has been drained by DataChannel.send. | ||
| reliableMessageBuffer.queue(DataPacketItem(ByteBuffer.wrap(packetBytes), dataPacket.sequence)) | ||
| reliableDataSequence++ | ||
| reliableMessageBuffer.trim(channel.bufferedAmount()) |
There was a problem hiding this comment.
🔴 Reliable publish crash during teardown
If disconnect or full reconnect disposes the channel after a successful send, bufferedAmount() can fail the publish. Channel disposal does not share reliableStateLock. If disposal clears the pointer between WebRTC’s Java check and native lookup, the app can crash.
Learn more
publishData calls the engine from the caller’s coroutine, and reliable sends take reliableStateLock. Room disconnect and full reconnect tear down the publisher separately. closeResources runs on the RTC executor and calls closeEarlyPublisher, which disposes the reliable channel without the send lock. In WebRTC M150, bufferedAmount() checks the Java native pointer before JNI reads it again, and dispose() releases and clears that pointer. The Java exception turns the accepted send into a failure; a JNI lookup of the cleared pointer is not catchable.
Example: A participant publishes while the room starts a full reconnect. WebRTC accepts the packet, then the RTC executor disposes the old publisher channel. Reading the amount from that old channel can return a publish failure even though WebRTC accepted the packet.
Recommended fix: Serialize the channel lookup, send, and buffered-amount read with disposal on the RTC executor. Acquire the reliable-state lock inside the executor work rather than waiting for the RTC executor while holding it. Keep sequence assignment and buffer mutation ordered with replay, and verify that a post-send trim cannot change an accepted publish into a failure.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
The IllegalStateException is caught by the surrounding try/catch in sendDataImpl, so it can't crash; at worst a send during teardown reports failure which is acceptable.
|
Diffuse output: AAR |
The reliable buffer was only trimmed when the data channel's bufferedAmount flow emitted. That flow is a StateFlow, and small packets leave the channel at once, so the value stays at 0 and never emits again due to conflation. With room metrics on by default, reliable packets a second piled up until the room disconnected if there weren't any large data packets to cause backpressure and have bufferedAmount emit values.
This change does a trim with the channel's live bufferedAmount() after every reliable send, as the JS SDK does. The flow collector stays to trim after a drain.
Fixes #1063
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com