Skip to content

Commit

Permalink
Dart: Fix assertion caused by receiving a notification message on a c…
Browse files Browse the repository at this point in the history
…losed stream
  • Loading branch information
inetic committed Aug 6, 2024
1 parent 8357855 commit 684db6e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions bindings/dart/lib/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,20 @@ class Client {
}

void _handleNotification(StreamSink<Object?> sink, Object? payload) {
if (payload is String) {
sink.add(null);
} else if (payload is Map && payload.length == 1) {
sink.add(payload.entries.single.value);
} else {
final error = Exception('invalid notification');
sink.addError(error);
try {
if (payload is String) {
sink.add(null);
} else if (payload is Map && payload.length == 1) {
sink.add(payload.entries.single.value);
} else {
final error = Exception('invalid notification');
sink.addError(error);
}
} catch (error) {
// We can get here if the `_controller` has been `close`d but the
// `_controller.onCancel` has not yet been executed (that's where the
// `Subscription` is removed from `_subscriptions`). We just ignore that
// error.
}
}
}
Expand Down

0 comments on commit 684db6e

Please sign in to comment.