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

Crash in core library: TypeError int is not a subtype of _FutureListener<dynamic, dynamic>? #43662

Closed
jonahwilliams opened this issue Oct 3, 2020 · 5 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant library-async type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jonahwilliams
Copy link
Contributor

While scrubbing through the flutter tool crash logs I've found a few that seem to be bugs in the dart core libraries. I do not have instructions to repro this - it seems fairly rare and not that severe but does seem to indicate that the future implementation has some edge cases.

_TypeError: type 'int' is not a subtype of type '_FutureListener<dynamic, dynamic>?'

  | at Future._removeListeners | (future_impl.dart:436)
-- | -- | --
  | at Future._propagateToListeners | (future_impl.dart:759)
  | at Future._completeWithValue | (future_impl.dart:529)
  | at Future._asyncCompleteWithValue.<anonymous closure> | (future_impl.dart:567)
  | at _rootRun | (zone.dart:1190)
  | at _CustomZone.run | (zone.dart:1093)
  | at _CustomZone.runGuarded | (zone.dart:997)
  | at _CustomZone.bindCallbackGuarded.<anonymous closure> | (zone.dart:1037)
  | at _microtaskLoop | (schedule_microtask.dart:41)
  | at _startMicrotaskLoop | (schedule_microtask.dart:50)
  | at _runPendingImmediateCallback | (isolate_patch.dart:118)
  | at _RawReceivePortImpl._handleMessage | (isolate_patch.dart:169)

Flutter Version dev/1.23.0-4.0.pre
Dart SDK version: 2.10.0-136.0.dev (dev) (Wed Sep 16 13:30:26 2020 -0700) on "macos_x64"

@mit-mit mit-mit added the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Oct 5, 2020
@mit-mit
Copy link
Member

mit-mit commented Oct 5, 2020

cc @lrhn

@lrhn lrhn added library-async type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 5, 2020
@lrhn
Copy link
Member

lrhn commented Oct 5, 2020

This looks like something which can happen if code attempts to remove listeners after the future has already been completed.
We use the same field to hold the listeners and the value, and use the state field to remember which mode we are in.
This is triggered by an _asyncCompleteWithValue (according to the stack trace).

If the state logic is correct, this cannot happen. It happens, so we probably have a bug.

It's not going to be easy to find, though. The class is for internal use, and it is not validating that it's being used correctly except through assertions. Unless we can trigger the bug with assertions enabled, it'll be hard to figure out who, if any, is calling _complete twice on the same future.

@lrhn
Copy link
Member

lrhn commented Apr 15, 2022

Since we haven't been able to reproduce this, I'll close the issue.
If we hear of a similar incident again, I'll know where to find it.

@lrhn lrhn closed this as completed Apr 15, 2022
@lrhn lrhn added the closed-obsolete Closed as the reported issue is no longer relevant label Apr 15, 2022
@blaugold
Copy link
Contributor

blaugold commented Apr 16, 2024

I'm seeing a similar error:

type 'Future<BannerAd?>' is not a subtype of type '_FutureListener<dynamic, dynamic>?'

String: type 'Future<BannerAd?>' is not a subtype of type '_FutureListener<dynamic, dynamic>?'
  File "future_impl.dart", line 501, in Future._removeListeners
  File "future_impl.dart", line 647, in Future._completeError
  File "future.dart", line 1333, in _completeWithErrorCallback
  File "future.dart", line 429, in new Future.delayed.<fn>
  File "ticker.dart", line 420, in TickerFuture.whenCompleteOrCancel.thunk
  File "timer_impl.dart", line 398, in _Timer._runTimers
  File "timer_impl.dart", line 429, in _Timer._handleMessage
  File "isolate_patch.dart", line 189, in _RawReceivePort._handleMessage

At the same time, I'm seeing this StackOverflowError. Maybe it's correlated somehow:

StackOverflowError: Stack Overflow
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  File "future_impl.dart", in Future._addListener
  ?, in ...
  ?, in ...
Dart SDK version: 3.1.4 (stable) (Tue Oct 17 14:55:53 2023 +0000) on "macos_arm64"

@lrhn
Copy link
Member

lrhn commented Apr 16, 2024

The stack overflow does ring a bell. I did a rewrite of Future that never landed (yet), but one bug I noticed and fixed was that there was no attempt to prevent a future being completed with itself.

Completer c = Completer<void>();
c.complete(c.future);

This sets up c.future to wait for itself. That's handled internally as pointing to itself as its source future, and forwarding _addListener calls to its source future. Which would precisely give this result.

That also means that _addListener throws, likely in the middle of doing something else, which can be why the future gets into an inconsistent state where it thinks it can be completed, even if it can't.

And the first error is also reproducible as:

void main() async {
  var completer = Completer<void>();
  await (completer
        ..complete(Future.delayed(Duration.zero, () => completer.future)))
      .future;
}

@lrhn lrhn reopened this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant library-async type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants