Skip to content
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

Regression in StackTrace within Chain.capture from package:stack_trace. #46326

Open
natebosch opened this issue Jun 10, 2021 · 6 comments
Open
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Comments

@natebosch
Copy link
Member

Somewhere between 2.12.0-13.0.dev and 2.12.0-29.0.dev there was a regression in StackTrace.current when used within the zone for a Chain.capture call.

Reproduction is using package:stack_trace.

import 'dart:async';

import 'package:stack_trace/stack_trace.dart';

void main() async {
  Future<void> callee() async {
    await Future(() {});
    print(StackTrace.current);
  }

  Future<void> caller() async {
    await callee();
  }

  await Chain.capture(() async {
    await caller();
  });
}

Running with 2.12.0-13.0.dev and earlier SDKs outputs a meaningful stacktrace:

#0      main.callee (package:stack_trace/repro.dart:8:22)
<asynchronous suspension>
dart-lang/tools#1817      main.callee (package:stack_trace/repro.dart)
dart-lang/stack_trace#2      main.caller (package:stack_trace/repro.dart:12:17)
dart-lang/tools#1818      main.<anonymous closure> (package:stack_trace/repro.dart:16:17)
dart-lang/tools#1819      Chain.capture.<anonymous closure> (package:stack_trace/src/chain.dart:94:24)
dart-lang/tools#1820      _rootRun (dart:async/zone.dart:1190:13)
dart-lang/tools#1821      _CustomZone.run (dart:async/zone.dart:1093:19)
dart-lang/stack_trace#7      _runZoned (dart:async/zone.dart:1630:10)
dart-lang/tools#1822      runZoned (dart:async/zone.dart:1550:10)
dart-lang/tools#1823      Chain.capture (package:stack_trace/src/chain.dart:92:12)
dart-lang/tools#1824     main (package:stack_trace/repro.dart:15:15)
dart-lang/tools#1825     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:311:19)
dart-lang/stack_trace#12     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Running with 2.12.0-29.dev and later SDKs outputs instead:

#0      main.callee (package:stack_trace/repro.dart:8:22)
<asynchronous suspension>
dart-lang/tools#1817      StackZoneSpecification._registerUnaryCallback.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart)
<asynchronous suspension>

The closure it references should be this one:

https://github.com/dart-lang/stacK_trace/blob/4755bcf8ab0258212f4767218fdeb8429f3e550e/lib/src/stack_zone_specification.dart#L126

cc @cskau-g

@ghost
Copy link

ghost commented Jun 14, 2021

Thanks Nate. I'll have a look.

@ghost
Copy link

ghost commented Jun 14, 2021

Bisects to e90967f which made --lazy-async-stacks default. (My CL)

One thing I notice is that it seems to be a behavioural change specific to StackTrace.current as:

  Future<void> callee() async { ...; throw 'callee throws!'; }
  await Chain.capture(() async { ... }, onError: (e, sc) { print("$e:\n$sc"); });

produces:

callee throws!
dart_46326.dart 9:5    main.callee
===== asynchronous gap ===========================
dart:async/zone.dart 1364:19                        _CustomZone.registerBinaryCallback
dart:async-patch/async_patch.dart 61:8              _asyncErrorWrapperHelper
dart_46326.dart        main.<fn>
package:stack_trace/src/chain.dart 94:24            Chain.capture.<fn>
dart:async/zone.dart 1428:13                        _rootRun
dart:async/zone.dart 1328:19                        _CustomZone.run
dart:async/zone.dart 1863:10                        _runZoned
dart:async/zone.dart 1785:10                        runZoned
package:stack_trace/src/chain.dart 92:12            Chain.capture
dart_46326.dart 17:15  main
dart:isolate-patch/isolate_patch.dart 283:19        _delayEntrypointInvocation.<fn>
dart:isolate-patch/isolate_patch.dart 184:12        _RawReceivePortImpl._handleMessage

which I believe is what you were expecting.

I'll dive into where that difference comes from and what the expected output of StackTrace.current is for this case.

@mkustermann
Copy link
Member

@natebosch If you use Chain.capture(), could you then also use Chain.current() instead of StackTrace.current? Would that fix your issue?

@natebosch
Copy link
Member Author

@natebosch If you use Chain.capture(), could you then also use Chain.current() instead of StackTrace.current? Would that fix your issue?

I suspect we could fix it that way. I haven't dug to find how challenging it might be, but it's the first option I describe in dart-lang/tools#1851

@radzish
Copy link

radzish commented Oct 31, 2021

Hello here, any progress on this?

@mraleph
Copy link
Member

mraleph commented Jul 10, 2023

I think this is fixed by dart-archive/stack_trace@d3e4c4d and a52f2b9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
Projects
None yet
Development

No branches or pull requests

4 participants