Repository navigation
High frequency crash - _TypeError at State.setState #138588
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: crashStack traces logged to the consoleStack traces logged to the consolecustomer: huggsy (g3)frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Copied from Google bug b/310712894:
An internal Google team is seeing as crash with over 5000 instances per day with this stack trace:
_TypeError
at State.setState (framework.dart:1223 )
at _AnimatedState._handleChange (transitions.dart:129 )
at _AnimatedState._handleChange (transitions.dart:128 )
at AnimationLocalListenersMixin.notifyListeners (listener_helpers.dart:161 )
at AnimationController._tick (animation_controller.dart:852 )
at AnimationController._tick (animation_controller.dart:841 )
at Ticker._tick (ticker.dart:249 )
at Ticker._tick (ticker.dart:243 )
at SchedulerBinding._invokeFrameCallback (binding.dart:1371 )
at SchedulerBinding.handleBeginFrame.<anonymous closure> (binding.dart:1218 )
at _LinkedHashMapMixin.forEach (compact_hash.dart:633 )
at SchedulerBinding.handleBeginFrame (binding.dart:1216 )
at SchedulerBinding._handleBeginFrame (binding.dart:1133 )
at SchedulerBinding._handleBeginFrame (binding.dart:1124 )
at _rootRunUnary (zone.dart:1415 )
at _rootRunUnary (zone.dart:1405 )
at _CustomZone.runUnary (zone.dart:1308 )
at _CustomZone.runUnaryGuarded (zone.dart:1217 )
at _invoke1 (hooks.dart:330 )
at PlatformDispatcher._beginFrame (platform_dispatcher.dart:350 )
at _beginFrame (hooks.dart:272 )
at _beginFrame (hooks.dart:270 )
We don't have a reproduction for this, but it's quite frequent, so I'm wondering if someone on the framework team could take a look in case it seems related to any recent changes.
This is occurring within a stack of completely Flutter framework code and the error message does not provide much context, so it's tricky to know where to start with reproducing this in the app. Any tips would be much appreciated here!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: crashStack traces logged to the consoleStack traces logged to the consolecustomer: huggsy (g3)frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Activity
HansMuller commentedon Nov 17, 2023
The code at the top of the stack hasn't changed in a year or more and unfortunately
_TypeErrordoesn't reveal much. The line that's failing is:Where
_elementis a StatefulElement.jonahwilliams commentedon Nov 17, 2023
TypeError would be because the element is null, I think the NPE is coerced to a TypeError. Potentially this is the element/context being used after the widget has been cleared, so something like a setState after an async call?
jacobsimionato commentedon Nov 17, 2023
Oh that seems likely. Thank you for the help! It's difficult to try to guess where that is happening based on the trace - I'll ask the app team to think of recent changes to their code that could hold a reference to context over an async call.
jacobsimionato commentedon Nov 19, 2023
From the app team on an internal bug:
Does it makes sense to guard this
setStatecall? Or is that really just hiding a programming error that will likely have other consequences anyway.Seeing as it's quite difficult to find the root cause of this in application code (there are few recent animation changes in their codebase and no obvious bugs in them), I'm searching for other ways to make this tractable. Is there any way the framework could detect this issue sooner and/or use a more informative error message?
I'll leave this without a priority tag so it can go through the proper triage process, but the internal bug is P1. I acknowledge it's still not clear if this issue is actionable for the Flutter team at all.
goderbauer commentedon Nov 22, 2023
I would also conclude from the stack trace that
_elementis likely null whensetStateis called here:flutter/packages/flutter/lib/src/widgets/transitions.dart
Lines 128 to 132 in cf09a8a
What is puzzling: The
_elementis only nulled out when the StatefulElement is unmounted after State.dispose has been called, see:flutter/packages/flutter/lib/src/widgets/framework.dart
Lines 2062 to 2078 in cf09a8a
In
_AnimatedState.disposewe remove the_handleChangelistener that is calling the problematicsetState:flutter/packages/flutter/lib/src/widgets/transitions.dart
Lines 123 to 126 in cf09a8a
So, in theory, at the point in time where
_elementis null, the_handleChangeshouldn't be registered anymore and it is a mystery to me right now why it would be called.In theory (see above) it shouldn't be necessary to guard the setState, so, yeah, I am afraid that doing that is just hiding some other error somewhere...
If we were able to repro this in a debug build, you'd likely get a better error message somewhere. In release builds a lot of the debug information is stripped out...
goderbauer commentedon Nov 28, 2023
I think we need some more context where/when this crash is happening or a repo case to make progress.
9 remaining items
github-actions commentedon Mar 1, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.goderbauer commentedon Mar 5, 2024
Good news, somebody was able to reproduce this crash in #144087 (comment). Based on that, I was able to identify that the crash was caused by #136608. I am reverting that change in #144579.
Revert "_DefaultTabControllerState should dispose all created TabCont…
Add regression test for TabBar crash (#144627)
github-actions commentedon Mar 20, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.Revert "_DefaultTabControllerState should dispose all created TabCont…