-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"await for" errors are handled too late #45645
Comments
Note that this also happens when using extension StreamExtension<T> on Stream<T> {
/// Workaround for dart-lang/sdk#45645.
CancelableFuture<void> forEachFixed(FutureOr<void> callback(T element)) {
var completer = new Completer<void>();
var subscription = this.listen(null, onError: completer.completeError, onDone: completer.complete);
subscription.onData((event) async {
subscription.pause();
try {
await callback(event);
subscription.resume();
} catch (error, stackTrace) {
subscription.cancel();
completer.completeError(error, stackTrace);
}
});
return completer.future;
}
} |
The issue with Our The reason your "fixed" See: #34775 |
/cc @mkustermann @cskau-g |
Errors that are thrown in the body of an
await for
within anasync
function aren't forwarded through that function's future until the next event is emitted by the stream in question. For example:This prints
1
, and then only after five seconds does it printcaught oh no
. This is a pretty substantial problem: certain streams may emit events separated by a large amount of time, and some (such as stdin) may never emit another event. This could cause the error to be silently ignored, potentially leading to deadlocks.Instead of this behavior, I would expect an error to immediately cancel the subscription to the stream and forward the error to the outer future.
The text was updated successfully, but these errors were encountered: