Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix timer keeps active when resampling disabled in some cases #97197

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

Merged

Conversation

wangying3426
Copy link
Contributor

@wangying3426 wangying3426 commented Jan 25, 2022

Fix timer still keeps active when resampling disabled.

The problem will occur like this:

  • A developer set resamplingEnabled to true.
  • When events received, a periodic timer for resampling will be started until all resamplers are finished. But if one event's timestamp is larger than current simple time, its resampler will keep resampling.
  • Then, the developer set resamplingEnabled to false, at this moment the periodic time still keeps active .

For example, flutter/engine#30422 shows a case that the timestamp of a fake event is much more than current sample time, so its resampler and the timer will keeps active for a very long time.

For the tests, an assert exception will occur and tests will failed if _timer?.cancel not be called.

Pending timers:
Timer (duration: 0:00:00.016667, periodic: true), created:
#0      new FakeTimer._ (package:fake_async/fake_async.dart:284:41)
#1      FakeAsync._createTimer (package:fake_async/fake_async.dart:248:27)
#2      FakeAsync.run.<anonymous closure> (package:fake_async/fake_async.dart:183:19)
#5      _Resampler.sample.<anonymous closure> (package:flutter/src/gestures/binding.dart:168:24)
#6      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1145:15)
#7      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1090:9)
#8      AutomatedTestWidgetsFlutterBinding.scheduleWarmUpFrame (package:flutter_test/src/binding.dart:1074:5)
#9      runApp (package:flutter/src/widgets/binding.dart:1037:7)
#10     TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:813:7)
<asynchronous suspension>
(elided 2 frames from dart:async)

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test:
A Timer is still pending even after the widget tree was disposed.
'package:flutter_test/src/binding.dart':
Failed assertion: line 1236 pos 12: '!timersPending'

When the exception was thrown, this was the stack:
#2      AutomatedTestWidgetsFlutterBinding._verifyInvariants (package:flutter_test/src/binding.dart:1236:12)
#3      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:821:7)
<asynchronous suspension>
(elided 2 frames from class _AssertionError)

The test description was:
  Timer should be canceled when resampling stopped
════════════════════════════════════════════════════════════════════════════════════════════════════
00:03 +1 -1: Timer should be canceled when resampling stopped [E]                                                                                                                                        
  Test failed. See exception logs above.
  The test description was: Timer should be canceled when resampling stopped
  
00:03 +1 -1: Some tests failed.    

@flutter-dashboard flutter-dashboard bot added f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels. labels Jan 25, 2022
@skia-gold
Copy link

Gold has detected about 6 new digest(s) on patchset 1.
View them at https://flutter-gold.skia.org/cl/github/97197

@skia-gold
Copy link

Gold has detected about 41 new digest(s) on patchset 2.
View them at https://flutter-gold.skia.org/cl/github/97197

@wangying3426 wangying3426 changed the title Fix timer may not be canceled when all resamplers stopped Fix timer keeps active when all resamplers stopped in some cases Jan 25, 2022
@skia-gold
Copy link

Gold has detected about 30 new digest(s) on patchset 3.
View them at https://flutter-gold.skia.org/cl/github/97197

@wangying3426 wangying3426 changed the title Fix timer keeps active when all resamplers stopped in some cases Fix timer keeps active when resampling disabled in some cases Jan 25, 2022
@skia-gold
Copy link

Gold has detected about 49 new digest(s) on patchset 4.
View them at https://flutter-gold.skia.org/cl/github/97197

@skia-gold
Copy link

Gold has detected about 50 new digest(s) on patchset 5.
View them at https://flutter-gold.skia.org/cl/github/97197

@skia-gold
Copy link

Gold has detected about 37 new digest(s) on patchset 6.
View them at https://flutter-gold.skia.org/cl/github/97197

@skia-gold
Copy link

Gold has detected about 12 new digest(s) on patchset 7.
View them at https://flutter-gold.skia.org/cl/github/97197

@skia-gold
Copy link

Gold has detected about 49 new digest(s) on patchset 8.
View them at https://flutter-gold.skia.org/cl/github/97197

@goderbauer
Copy link
Member

goderbauer commented Jan 26, 2022

@wangying3426 Looks like this PR is addressing two different issues? Can you please split it in two so we can evaluate (and land) them separately?

@goderbauer goderbauer self-requested a review January 26, 2022 22:35
@skia-gold
Copy link

Gold has detected about 24 new digest(s) on patchset 9.
View them at https://flutter-gold.skia.org/cl/github/97197

@wangying3426
Copy link
Contributor Author

wangying3426 commented Jan 27, 2022

@goderbauer I have modified this PR to focus only one issue and updated the first comments.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@goderbauer
Copy link
Member

@wangying3426 Can you rebase this to the latest master to make the checks pass, please?

@christopherfujino christopherfujino removed their request for review February 7, 2022 18:18
@wangying3426 wangying3426 force-pushed the fix_resamper_timer_not_cancel branch 2 times, most recently from 553618c to 2fbebfb Compare February 8, 2022 01:27
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • Please get at least one approved review if you are already a member or two member reviews if you are not a member before re-applying this label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@fluttergithubbot fluttergithubbot merged commit 499e900 into flutter:master Feb 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2022
@wangying3426
Copy link
Contributor Author

@goderbauer Could you please also review this related PR flutter/engine#30422 ? thanks.

@goderbauer
Copy link
Member

@wangying3426 It would be best to have that one reviewed by an engine expert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants