Skip to content

Commit af79f2f

Browse files
brianquinlanCommit Queue
authored andcommitted
[io] Fix a bug where Socket.addStream never completes after the socket is destroyed.
Bug:#54735 Change-Id: I8895ff6271eb1019ddad13c171f36cbec5fd84cd TEST=tests/standalone/io/client_socket_destroy_and_add_stream_test.dart Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348764 Commit-Queue: Brian Quinlan <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]>
1 parent 6293002 commit af79f2f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

sdk/lib/_internal/vm/bin/socket_patch.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,8 @@ class _SocketStreamConsumer implements StreamConsumer<List<int>> {
21842184
assert(buffer == null);
21852185
done();
21862186
}, cancelOnError: true);
2187+
} else {
2188+
done();
21872189
}
21882190
return completer.future;
21892191
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Tests that adding a stream to a `Socket` that has been `destroy`ed returns
6+
// a `Future` that completes.
7+
8+
import "dart:async";
9+
import "dart:io";
10+
11+
import "package:async_helper/async_helper.dart";
12+
import "package:expect/expect.dart";
13+
14+
void main() async {
15+
asyncStart();
16+
17+
final server = await ServerSocket.bind("127.0.0.1", 0);
18+
late final Socket connectedSocket;
19+
server.listen((socket) {
20+
// Note: must keep socket alive for the duration of the test.
21+
// Otherwise GC might collect it and and shutdown this side of socket
22+
// which would cause writing to abort.
23+
connectedSocket = socket;
24+
// Passive block data by not subscribing to socket.
25+
});
26+
27+
final client = await Socket.connect("127.0.0.1", server.port);
28+
client.listen((data) {}, onDone: server.close);
29+
client.add(new List.filled(1024 * 1024, 0));
30+
client.destroy();
31+
await client.addStream(Stream.fromIterable([
32+
[1, 2, 3, 4]
33+
]));
34+
asyncEnd();
35+
}

0 commit comments

Comments
 (0)