Skip to content

Commit a0c2791

Browse files
a-sivaCommit Queue
authored and
Commit Queue
committed
[stable][IO] - Use try/catch in lookupAddresses instead of Future error.
Applying patch from @aam for using try/catch in lookupAddresses instead of Future error. This cherry pick into the stable branch is to ensure we address the expedient issue in #53334 TEST=new test added. Bug: #53334 Change-Id: Ia5375cbd118d8d6437cf6869383f173cab48aa3f Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/323684 Cherry-pick-request: #53450 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324569 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
1 parent 348c55f commit a0c2791

File tree

3 files changed

+83
-4
lines changed

3 files changed

+83
-4
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ This is a patch release that:
77
For example `final x = { for (var (int a,) in someList) a: a };`
88
(issue [#53358])
99

10+
- Fixes an expedient issue of users seeing an unhandled
11+
exception pause in the debugger, please see
12+
https://github.com/dart-lang/sdk/issues/53450 for more
13+
details.
14+
The fix uses try/catch in lookupAddresses instead of
15+
Future error so that we don't see an unhandled exception
16+
pause in the debugger (issue [#53334])
17+
1018
[#53358]: https://github.com/dart-lang/sdk/issues/53358
19+
[#53334]: https://github.com/dart-lang/sdk/issues/53334
1120

1221
## 3.1.1 - 2023-09-07
1322

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) 2023, 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+
// VMOptions=--verbose_debug
5+
6+
// Test checks to make sure we don't encounter any unhandled exceptions
7+
// in the URL lookup code.
8+
// (please see https://github.com/dart-lang/sdk/issues/53334 for more details).
9+
10+
import 'dart:developer';
11+
import 'dart:io';
12+
13+
import 'package:expect/expect.dart';
14+
15+
import 'common/service_test_common.dart';
16+
import 'common/test_helper.dart';
17+
18+
// AUTOGENERATED START
19+
//
20+
// Update these constants by running:
21+
//
22+
// dart runtime/observatory/tests/service/update_line_numbers.dart <test.dart>
23+
//
24+
const int LINE_0 = 46;
25+
// AUTOGENERATED END
26+
const String file = "break_on_unhandled_exception_test.dart";
27+
28+
Future<int> testFunction() async {
29+
try {
30+
var client = new HttpClient();
31+
final urlstr = 'https://www.bbc.co.uk/';
32+
final uri = Uri.parse(urlstr);
33+
var response = await client.getUrl(uri);
34+
Expect.equals(urlstr, response.uri.toString());
35+
return 0;
36+
} catch (e) {
37+
print(e.toString());
38+
return 1;
39+
}
40+
}
41+
42+
void testMain() async {
43+
debugger();
44+
final ret = await testFunction();
45+
Expect.equals(ret, 0);
46+
print("Done"); // LINE_0
47+
}
48+
49+
final tests = <IsolateTest>[
50+
hasStoppedAtBreakpoint,
51+
52+
// Add breakpoint
53+
setBreakpointAtUriAndLine(file, LINE_0),
54+
55+
resumeIsolate,
56+
57+
hasStoppedAtBreakpoint,
58+
stoppedAtLine(LINE_0),
59+
resumeIsolate,
60+
];
61+
62+
void main(args) => runIsolateTests(
63+
args,
64+
tests,
65+
'break_on_unhandled_exception_test.dart',
66+
pause_on_unhandled_exceptions: true,
67+
testeeConcurrent: testMain,
68+
);

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,10 @@ base class _NativeSocket extends _NativeSocketNativeWrapper
627627
// Only report an error if no address lookups were sucessful.
628628
var anySuccess = false;
629629

630-
void lookupAddresses(InternetAddressType type, Completer<void> done) {
631-
lookup(host, type: type).then((addresses) {
630+
void lookupAddresses(
631+
InternetAddressType type, Completer<void> done) async {
632+
try {
633+
final addresses = await lookup(host, type: type);
632634
anySuccess = true;
633635
if (done.isCompleted) {
634636
// By the time lookup is done, [connectNext] might have
@@ -637,14 +639,14 @@ base class _NativeSocket extends _NativeSocketNativeWrapper
637639
}
638640
controller.add(addresses);
639641
done.complete();
640-
}, onError: (e, st) {
642+
} catch (e, st) {
641643
if (done.isCompleted) {
642644
// By the time lookup is done, [connectNext] might have
643645
// been able to connect to one of the resolved addresses.
644646
return;
645647
}
646648
done.completeError(e, st);
647-
});
649+
}
648650
}
649651

650652
const concurrentLookupDelay = Duration(milliseconds: 10);

0 commit comments

Comments
 (0)