Skip to content

Consider adding support to --lazy-async-stacks for Future.timeout() #40815

@mkustermann

Description

@mkustermann

Some g3 users use Future.timeout() in code, e.g.:

import 'dart:async';

main() async {
  await bar();
}
Future bar() async {
  await (foo().timeout(Duration(seconds: 1)));
}
Future foo() async {
  await 0;
  throw 'a';
}

Though the --lazy-async-stacks implemementation looses track of the awaiter of the Future returned by .timeout():

% out/ReleaseX64/dart --lazy-async-stacks --no-causal-async-stacks async.dart
Unhandled exception:
a
#0      foo (file:///.../test.dart:13:3)
<asynchronous suspension>
#1      Future.timeout.<anonymous closure> (dart:async/future_impl.dart)
<asynchronous suspension>

The implementation looks like this (see future_impl.dart

  Future<T> timeout(Duration timeLimit, {FutureOr<T> onTimeout()}) {
    _Future<T> result = new _Future<T>();
    ...
    this.then((T v) {
      if (timer.isActive) {
        timer.cancel();
        result._completeWithValue(v);
      }
      ...
    });
    return result;
  }
}

We can consider adding special support for unwinding in this case by recognizing the inner closure in timeout() and knowing that the result variable will be available in the context.

b/297400933

/cc @cskau-g @mraleph

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions