Skip to content

Commit

Permalink
[stable][IO] - Use try/catch in lookupAddresses instead of Future error.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
a-siva authored and Commit Queue committed Sep 11, 2023
1 parent 348c55f commit a0c2791
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ This is a patch release that:
For example `final x = { for (var (int a,) in someList) a: a };`
(issue [#53358])

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

[#53358]: https://github.com/dart-lang/sdk/issues/53358
[#53334]: https://github.com/dart-lang/sdk/issues/53334

## 3.1.1 - 2023-09-07

Expand Down
68 changes: 68 additions & 0 deletions pkg/vm_service/test/break_on_unhandled_exception_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--verbose_debug

// Test checks to make sure we don't encounter any unhandled exceptions
// in the URL lookup code.
// (please see https://github.com/dart-lang/sdk/issues/53334 for more details).

import 'dart:developer';
import 'dart:io';

import 'package:expect/expect.dart';

import 'common/service_test_common.dart';
import 'common/test_helper.dart';

// AUTOGENERATED START
//
// Update these constants by running:
//
// dart runtime/observatory/tests/service/update_line_numbers.dart <test.dart>
//
const int LINE_0 = 46;
// AUTOGENERATED END
const String file = "break_on_unhandled_exception_test.dart";

Future<int> testFunction() async {
try {
var client = new HttpClient();
final urlstr = 'https://www.bbc.co.uk/';
final uri = Uri.parse(urlstr);
var response = await client.getUrl(uri);
Expect.equals(urlstr, response.uri.toString());
return 0;
} catch (e) {
print(e.toString());
return 1;
}
}

void testMain() async {
debugger();
final ret = await testFunction();
Expect.equals(ret, 0);
print("Done"); // LINE_0
}

final tests = <IsolateTest>[
hasStoppedAtBreakpoint,

// Add breakpoint
setBreakpointAtUriAndLine(file, LINE_0),

resumeIsolate,

hasStoppedAtBreakpoint,
stoppedAtLine(LINE_0),
resumeIsolate,
];

void main(args) => runIsolateTests(
args,
tests,
'break_on_unhandled_exception_test.dart',
pause_on_unhandled_exceptions: true,
testeeConcurrent: testMain,
);
10 changes: 6 additions & 4 deletions sdk/lib/_internal/vm/bin/socket_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,10 @@ base class _NativeSocket extends _NativeSocketNativeWrapper
// Only report an error if no address lookups were sucessful.
var anySuccess = false;

void lookupAddresses(InternetAddressType type, Completer<void> done) {
lookup(host, type: type).then((addresses) {
void lookupAddresses(
InternetAddressType type, Completer<void> done) async {
try {
final addresses = await lookup(host, type: type);
anySuccess = true;
if (done.isCompleted) {
// By the time lookup is done, [connectNext] might have
Expand All @@ -637,14 +639,14 @@ base class _NativeSocket extends _NativeSocketNativeWrapper
}
controller.add(addresses);
done.complete();
}, onError: (e, st) {
} catch (e, st) {
if (done.isCompleted) {
// By the time lookup is done, [connectNext] might have
// been able to connect to one of the resolved addresses.
return;
}
done.completeError(e, st);
});
}
}

const concurrentLookupDelay = Duration(milliseconds: 10);
Expand Down

0 comments on commit a0c2791

Please sign in to comment.