Skip to content

Commit 7d2d87e

Browse files
authored
Fix Connection reset by peer in protocol error tests (#1786)
1 parent e70a41b commit 7d2d87e

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

.github/workflows/cupertino.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ on:
99
- '.github/workflows/cupertino.yml'
1010
- 'pkgs/cupertino_http/**'
1111
- 'pkgs/http_client_conformance_tests/**'
12+
- 'pkgs/web_socket_conformance_tests/**'
1213
pull_request:
1314
paths:
1415
- '.github/workflows/cupertino.yml'
1516
- 'pkgs/cupertino_http/**'
1617
- 'pkgs/http_client_conformance_tests/**'
18+
- 'pkgs/web_socket_conformance_tests/**'
1719
schedule:
1820
- cron: "0 0 * * 0"
1921

pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_server.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const _webSocketGuid = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
1414
/// WebSocket upgrade.
1515
void hybridMain(StreamChannel<Object?> channel) async {
1616
late final HttpServer server;
17-
server = (await HttpServer.bind('localhost', 0))
18-
..listen((request) async {
17+
server = await HttpServer.bind('localhost', 0);
18+
runZonedGuarded(() {
19+
server.listen((request) async {
1920
var key = request.headers.value('Sec-WebSocket-Key');
2021
var digest = sha1.convert('$key$_webSocketGuid'.codeUnits);
2122
var accept = base64.encode(digest.bytes);
@@ -28,7 +29,14 @@ void hybridMain(StreamChannel<Object?> channel) async {
2829
final socket = await request.response.detachSocket();
2930
socket.write('marry had a little lamb whose fleece was white as snow');
3031
});
31-
32+
}, (e, s) {
33+
// dart:io sometimes asynchronously throws a `SocketException` with
34+
// `errorCode` 54.
35+
// See https://github.com/dart-lang/http/pull/1786 for a full traceback.
36+
if (e is! SocketException || e.osError?.errorCode != 54) {
37+
throw e as Exception;
38+
}
39+
});
3240
channel.sink.add(server.port);
3341

3442
await channel

0 commit comments

Comments
 (0)