Skip to content

Commit 07aa0dc

Browse files
Merge pull request #1186 from zino-hofmann/macros/fix_rebasing
fix `SocketClient` to close subscription on socket close
2 parents a19958f + c113458 commit 07aa0dc

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/graphql/lib/src/links/websocket_link/websocket_client.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,19 @@ class SocketClient {
495495
.where((message) => message is SubscriptionComplete)
496496
.take(1);
497497

498-
subscriptionComplete.listen((_) => response.close());
498+
subscriptionComplete.listen(
499+
(_) => response.close(),
500+
onDone: () {
501+
if (!config.autoReconnect) {
502+
response.close();
503+
}
504+
},
505+
onError: (_) {
506+
if (!config.autoReconnect) {
507+
response.close();
508+
}
509+
},
510+
);
499511

500512
dataErrorComplete
501513
.where((message) => message is SubscriptionData)

packages/graphql/test/websocket_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ Future<void> main() async {
613613
operation: Operation(document: gql('subscription {}')),
614614
);
615615
final waitForConnection = true;
616-
socketClient.subscribe(payload, waitForConnection);
616+
var subscription = socketClient.subscribe(payload, waitForConnection);
617+
var isEmpty = subscription.isEmpty;
617618

618619
await expectLater(
619620
socketClient.connectionState,
@@ -638,6 +639,8 @@ Future<void> main() async {
638639

639640
expect(
640641
socketClient.socketChannel!.closeCode, WebSocketStatus.normalClosure);
642+
643+
expect(await isEmpty.timeout(const Duration(seconds: 1)), true);
641644
});
642645
}, tags: "integration");
643646

0 commit comments

Comments
 (0)