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

Make realAsyncZone run microtasks and timers in the correct zone. #164982

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lrhn
Copy link
Contributor

@lrhn lrhn commented Mar 11, 2025

Current implementation runs timers and microtask callbacks in the root zone. That assumes that the top-level scheduleMicrotask or Timer constructors have been used, which have so far wrapped the callback with runCallbackGuarded before calling the zone implementation.
That means that doing zone.scheduleMicrotask directly would not ensure that the microtask was run in the correct zone. If a run handler throws, it wouldn't be caught.

This change makes the realAsyncZone do whatever the root zone would do if its ZoneDelegate got called with the intended zone and arguments. That should be consistent with the current behavior, and be compatible with incoming bug-fixes to the platform Zone behavior.

Prepares Flutter for landing https://dart-review.googlesource.com/c/sdk/+/406961
which is currently blocked (so this indirectly blocks fixing the dart-lang/sdk#59913).

Adds test to check that the callbacks do run in the expected zone. Otherwise all existing tests should keep running, and they should keep doing so when the Dart CL lands. Currently that CL only breaks one test, the dev/automated_tests/test_smoke_test/fail_test_on_exception_after_test.dart test which threw the error-after-test in the root zone instead of the test zone. This change fixes that.

(This is a copy of #162731 merged to head, to see if the goldens change is spurious. It seems so.)

lrhn added 3 commits March 11, 2025 16:37
Current implementation runs timers and microtask callbacks in the root zone.
That assumes that the top-level `scheduleMicrotask` or `Timer` constructors
have been used, which have so far wrapped the callback with `runCallbackGuarded`
before calling the zone implementation.
That means that doing `zone.scheduleMicrotask` directly would not ensure
that the microtask was run in the correct zone. If a `run` handler throws,
it wouldn't be caught.

This change makes the `realAsyncZone` do whatever the root zone would
do if its `ZoneDelegate` got called with the intended zone and arguments.
That should be consistent with the current behavior, and be compatible
with changes to the platform `Zone` behavior.
@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Mar 11, 2025
@lrhn
Copy link
Contributor Author

lrhn commented Mar 12, 2025

Does seem that there are no golden issues. PTAL either this or #162731 to get the Dart SDK CL unblocked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant