dart-lang / web_socket_channel

StreamChannel wrappers for WebSockets.
https://pub.dev/packages/web_socket_channel
BSD 3-Clause "New" or "Revised" License
417 stars 109 forks source link

Program never exits when cancelling the `StreamSubscription` of `WebSocketChannel.stream` #228

Open osaxma opened 2 years ago

osaxma commented 2 years ago

The following program will never exit:

import 'package:web_socket_channel/web_socket_channel.dart';

void main() async {
  final conn = WebSocketChannel.connect(Uri.parse('ws://localhost:8000/ws'));

  final sub = conn.stream.listen(null);

  await Future.delayed(Duration(seconds: 2));
  await sub.cancel(); // <~~~ when commenting this out, the program exits normally (removing await won't change a thing)
  await conn.sink.close(1000, 'normal closure');
}

To reproduce:

Additional info:

osaxma commented 2 years ago

Websocket from dart:io has the same issue so I filed one at: https://github.com/dart-lang/sdk/issues/49777

I haven't tested the html version for web.

I'll leave this open for visibility but feel free to close it.