Fix `Connection reset by peer` in protocol error tests (#1786)
diff --git a/.github/workflows/cupertino.yml b/.github/workflows/cupertino.yml
index 73f070b..e2d92d1 100644
--- a/.github/workflows/cupertino.yml
+++ b/.github/workflows/cupertino.yml
@@ -9,11 +9,13 @@
- '.github/workflows/cupertino.yml'
- 'pkgs/cupertino_http/**'
- 'pkgs/http_client_conformance_tests/**'
+ - 'pkgs/web_socket_conformance_tests/**'
pull_request:
paths:
- '.github/workflows/cupertino.yml'
- 'pkgs/cupertino_http/**'
- 'pkgs/http_client_conformance_tests/**'
+ - 'pkgs/web_socket_conformance_tests/**'
schedule:
- cron: "0 0 * * 0"
diff --git a/pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_server.dart b/pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_server.dart
index 8760bb9..a40fc1f 100644
--- a/pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_server.dart
+++ b/pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_server.dart
@@ -14,8 +14,9 @@
/// WebSocket upgrade.
void hybridMain(StreamChannel<Object?> channel) async {
late final HttpServer server;
- server = (await HttpServer.bind('localhost', 0))
- ..listen((request) async {
+ server = await HttpServer.bind('localhost', 0);
+ runZonedGuarded(() {
+ server.listen((request) async {
var key = request.headers.value('Sec-WebSocket-Key');
var digest = sha1.convert('$key$_webSocketGuid'.codeUnits);
var accept = base64.encode(digest.bytes);
@@ -28,7 +29,14 @@
final socket = await request.response.detachSocket();
socket.write('marry had a little lamb whose fleece was white as snow');
});
-
+ }, (e, s) {
+ // dart:io sometimes asynchronously throws a `SocketException` with
+ // `errorCode` 54.
+ // See https://github.com/dart-lang/http/pull/1786 for a full traceback.
+ if (e is! SocketException || e.osError?.errorCode != 54) {
+ throw e as Exception;
+ }
+ });
channel.sink.add(server.port);
await channel