@@ -551,10 +551,12 @@ class TransportWsClientOptions {
551
551
class _Connected {
552
552
final WebSocketChannel socket;
553
553
final Future <void > throwOnClose;
554
+ final Future <LikeCloseEvent ?> likeCloseEvent;
554
555
555
556
_Connected (
556
557
this .socket,
557
558
this .throwOnClose,
559
+ this .likeCloseEvent,
558
560
);
559
561
}
560
562
@@ -879,9 +881,26 @@ class _ConnectionState {
879
881
retries = 0 ; // reset the retries on connect
880
882
final _completer = Completer <void >();
881
883
errorOrClosed (_completer.completeError);
884
+ // workground for dart linux bug: complete error not being caught by try..catch block
885
+ final _likeCloseEventCompleter = Completer <LikeCloseEvent ?>();
882
886
connected (_Connected (
883
887
socket,
884
- _completer.future,
888
+ _completer.future.catchError ((err) {
889
+ // workground for dart linux bug: complete error not being caught by try..catch block
890
+ // if the connection is closed, the error is not fatal
891
+ if (err is LikeCloseEvent ) {
892
+ if (! _likeCloseEventCompleter.isCompleted) {
893
+ _likeCloseEventCompleter.complete (err);
894
+ }
895
+ return ;
896
+ }
897
+ throw err;
898
+ }).whenComplete (() {
899
+ if (! _likeCloseEventCompleter.isCompleted) {
900
+ _likeCloseEventCompleter.complete (null );
901
+ }
902
+ }),
903
+ _likeCloseEventCompleter.future,
885
904
));
886
905
} catch (err) {
887
906
// stop reading messages as soon as reading breaks once
@@ -930,6 +949,7 @@ class _ConnectionState {
930
949
931
950
final socket = _connection.socket;
932
951
final throwOnClose = _connection.throwOnClose;
952
+ final likeCloseEvent = _connection.likeCloseEvent;
933
953
934
954
// if the provided socket is in a closing state, wait for the throw on close
935
955
// TODO: WebSocketChannel should have a `state` getter
@@ -972,6 +992,7 @@ class _ConnectionState {
972
992
// or
973
993
throwOnClose,
974
994
]),
995
+ waitForLikeCloseEvent: likeCloseEvent,
975
996
);
976
997
}
977
998
}
@@ -1013,6 +1034,7 @@ class _Client extends TransportWsClient {
1013
1034
final socket = _c.socket;
1014
1035
final release = _c.release;
1015
1036
final waitForReleaseOrThrowOnClose = _c.waitForReleaseOrThrowOnClose;
1037
+ final waitForLikeCloseEvent = _c.waitForLikeCloseEvent;
1016
1038
// print("isolate debug name: ${Isolate.current.debugName}");
1017
1039
// print(payload.operation.toString());
1018
1040
// print(payload.variables.toString());
@@ -1072,6 +1094,12 @@ class _Client extends TransportWsClient {
1072
1094
// whatever happens though, we want to stop listening for messages
1073
1095
await waitForReleaseOrThrowOnClose.whenComplete (unlisten);
1074
1096
1097
+ // workground for dart linux bug: complete error not being caught by try..catch block
1098
+ final likeCloseEvent = await waitForLikeCloseEvent;
1099
+ if (likeCloseEvent != null ) {
1100
+ throw likeCloseEvent;
1101
+ }
1102
+
1075
1103
return ; // completed, shouldnt try again
1076
1104
} catch (errOrCloseEvent) {
1077
1105
if (! state.shouldRetryConnectOrThrow (errOrCloseEvent)) return ;
@@ -1123,11 +1151,13 @@ class _Connection {
1123
1151
final WebSocketChannel socket;
1124
1152
final Completer <void > release;
1125
1153
final Future <void > waitForReleaseOrThrowOnClose;
1154
+ final Future <LikeCloseEvent ?> waitForLikeCloseEvent;
1126
1155
1127
1156
_Connection ({
1128
1157
required this .socket,
1129
1158
required this .release,
1130
1159
required this .waitForReleaseOrThrowOnClose,
1160
+ required this .waitForLikeCloseEvent,
1131
1161
});
1132
1162
}
1133
1163
0 commit comments