Repository navigation
fix: make DataStreamError a LiveKitException - #1294
Merged
Merged
Conversation
A data stream write cut off by disposing the room fails on native with a DataStreamError, which only implemented Exception, so apps catching LiveKitException missed it. DataStreamError now implements LiveKitException; its toString() is unchanged. Also correct the AbnormalEnd comment: the reason covers local disconnect or dispose and I/O failures, not only a remote participant leaving. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hiroshihorie
marked this pull request as ready for review
November 17, 2026 07:16
hiroshihorie
requested review from
changt,
cloudwebrtc and
xianshijing-lk
as code owners
November 17, 2026 07:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DataStreamErrorwas declaredimplements Exception, so it was not aLiveKitException, the base type the SDK documents for what it throws. An app that catches stream writes withon LiveKitExceptionmissed it.Since data streams v2 (#1166), native writes go through the Rust core. A write still in the core when the room is disposed fails with
DataStreamError(AbnormalEnd), which comes from the core'sInternalDataStreamExceptionvia the catch-all intoLKError. The e2e scenario "Dispose during backpressured stream writes" expects every such write to fail with aLiveKitException, and found this.Change
DataStreamErrornowimplements LiveKitException(the base class's constructor is private, so it can't be extended).messagegets@override;toString()is unchanged.DataStreamErrorReason.AbnormalEndsaid "closed abnormally by remote participant". It now lists everything that maps to this reason: the sender leaving mid-stream, the local room disconnecting or being disposed, an I/O failure, and the FFI catch-all. The enum itself is unchanged.What I checked
lib/: none behaves differently. The only supertype check isChecker.messageFor(error is LiveKitException), and connection checks don't use data streams. Every other check names a specific type thatDataStreamErrordoesn't match:ConnectException,CertificatePinningException,NegotiationError,UnexpectedConnectionState,MediaConnectException,RpcError,PlatformException, orffi.DataStreamException. The data stream and RPC code catches errors without checking the type, then logs them or wraps them inRpcErrorfrome.toString(). That string comes fromtoString(), which is unchanged.v2.13.2was tagged fromrelease/2.13.2and contains only a flutter_webrtc bump. Before Data streams v2 #1166 onmain, a write on a closed engine failed withUnexpectedConnectionState(Fix waiting for the data channel send buffer to drain #1267/Announce engine closure on disposal and terminal reconnect failure #1268, also unreleased). In 2.13.x, by reading the code: a write waiting on the buffer polled forever, because dispose didn't announce engine closure yet. A write already sending hit the closed channel and failed with aPlatformException; the e2e case's note on Send reliable data after a full reconnect instead of dropping it #1277 agrees. So this is not a regression from a release. In 2.13.xDataStreamErrorwas never aLiveKitExceptionfor any reason, readers included, so this is new behaviour for users.engine.waitForBufferStatusLowand fails withUnexpectedConnectionState. That is already aLiveKitException. After this change both platforms fail the write with aLiveKitException, but the concrete types still differ: web givesUnexpectedConnectionState, native givesDataStreamError(AbnormalEnd). On native, a write issued after the engine has closed still getsUnexpectedConnectionStatefrom_ensureOpen, as before.dart-apitool diffagainstorigin/main(298cc62) reports "No breaking changes!", with one minor change:Super Type "LiveKitException" added (CI04). The tool rates an added supertype as a minor change. The changeset ispatchfor now; minor vs patch is the owner's call..changes/buffer-wait-typed-errorread slightly inconsistently on native. That one says writes on a closed engine fail withUnexpectedConnectionState, which holds for a write issued after the engine closed. A write already in the core when the room is disposed getsDataStreamError(now aLiveKitException). Whoever writes the release notes should reconcile the two lines. I left the other changeset unchanged.Tests
Added
writes cut off by disposing the room fail with a LiveKitExceptiontotest/core/data_stream_v2_test.dart. It runs the real Rust core through the mock container: it starts 50 unawaited 30 KB writes on a byte stream, disposes the room, and checks that at least one write failed and that every failure is aLiveKitException. Without the change all 50 fail withDataStreamError, which is not aLiveKitException, and the test fails. With it, the test passed 5 times out of 5.Holding a write in a full send buffer doesn't reproduce this on native: the core's outgoing queue is unbounded, so writes return as soon as the core has queued them.
flutter analyze,flutter test,dart format,import_sorter, andcheck_versionall pass.🤖 Generated with Claude Code