Skip to content

Commit 791163e

Browse files
bkonyiCommit Queue
authored and
Commit Queue
committed
[ dart:io ] Fix minor bugs in network profiler
Fixes issues where: - Socket profile addresses were set using `InternetAddress.toString()` instead of `InternetAddress.address` - HTTP requests were not being marked as completed if `listen(...)` was not called on the `HttpClientResponse` - An exception could be thrown from profiling code if an HTTP response was completed after it was already completed with an error Change-Id: I572928b77c4b1eb241acc7ec29f0e95dd7b2da8a CoreLibraryReviewExempt: Only impacts dart:io network profiling logic Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375800 Commit-Queue: Ben Konyi <[email protected]> Reviewed-by: Derek Xu <[email protected]> Auto-Submit: Ben Konyi <[email protected]>
1 parent 3d33ef5 commit 791163e

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

Diff for: sdk/lib/_http/http_impl.dart

+22-16
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ class _HttpProfileData {
195195
}
196196

197197
void finishResponse() {
198+
// Guard against the response being completed more than once or being
199+
// completed before the response actually finished starting.
200+
if (responseInProgress != true) return;
198201
responseInProgress = false;
199202
responseEndTimestamp = DateTime.now().microsecondsSinceEpoch;
200203
requestEvent('Content Download');
@@ -600,6 +603,9 @@ class _HttpClientResponse extends _HttpInboundMessageListInt
600603
super(_incoming) {
601604
// Set uri for potential exceptions.
602605
_incoming.uri = _httpRequest.uri;
606+
// Ensure the response profile is completed, even if the response stream is
607+
// never actually listened to.
608+
_incoming.dataDone.then((_) => _profileData?.finishResponse());
603609
}
604610

605611
static HttpClientResponseCompressionState _getCompressionState(
@@ -708,22 +714,22 @@ class _HttpClientResponse extends _HttpInboundMessageListInt
708714
return data;
709715
});
710716
}
711-
return stream.listen(onData, onError: (e, st) {
712-
_profileData?.finishResponseWithError(e.toString());
713-
if (onError == null) {
714-
return;
715-
}
716-
if (onError is void Function(Object, StackTrace)) {
717-
onError(e, st);
718-
} else {
719-
(onError as void Function(Object))(e);
720-
}
721-
}, onDone: () {
722-
_profileData?.finishResponse();
723-
if (onDone != null) {
724-
onDone();
725-
}
726-
}, cancelOnError: cancelOnError);
717+
return stream.listen(
718+
onData,
719+
onError: (e, st) {
720+
_profileData?.finishResponseWithError(e.toString());
721+
if (onError == null) {
722+
return;
723+
}
724+
if (onError is void Function(Object, StackTrace)) {
725+
onError(e, st);
726+
} else {
727+
(onError as void Function(Object))(e);
728+
}
729+
},
730+
onDone: onDone,
731+
cancelOnError: cancelOnError,
732+
);
727733
}
728734

729735
Future<Socket> detachSocket() {

Diff for: sdk/lib/io/network_profiling.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ abstract class _SocketProfile {
253253
break;
254254
case _SocketProfileType.address:
255255
assert(object is InternetAddress);
256-
stats.address = (object as InternetAddress).toString();
256+
final internetAddress = object as InternetAddress;
257+
stats.address = (internetAddress.type == InternetAddress.anyIPv6 ||
258+
internetAddress.type == InternetAddress.loopbackIPv6)
259+
? '[${internetAddress.address}]'
260+
: internetAddress.address;
257261
break;
258262
case _SocketProfileType.port:
259263
assert(object is int);

0 commit comments

Comments
 (0)