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

[unified_analytics] Crash on flutter master branch #252

Closed
dcharkes opened this issue Mar 14, 2024 · 10 comments
Closed

[unified_analytics] Crash on flutter master branch #252

dcharkes opened this issue Mar 14, 2024 · 10 comments

Comments

@dcharkes
Copy link
Contributor

$ flutter --version

Unhandled exception:
type 'Null' is not a subtype of type 'int' in type cast
#0      Session._refreshSessionData.parseContents (package:unified_analytics/src/session.dart:94:43)
#1      Session._refreshSessionData (package:unified_analytics/src/session.dart:98:7)
#2      new Session (package:unified_analytics/src/session.dart:37:27)
#3      new AnalyticsImpl (package:unified_analytics/src/analytics.dart:429:23)
#4      new Analytics (package:unified_analytics/src/analytics.dart:87:12)
#5      getAnalytics (package:flutter_tools/src/reporting/unified_analytics.dart:51:10)
#6      runInContext.<anonymous closure> (package:flutter_tools/src/context_runner.dart:92:24)
#7      AppContext._generateIfNecessary.<anonymous closure> (package:flutter_tools/src/base/context.dart:107:42)
#8      _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:543:23)
#9      AppContext._generateIfNecessary (package:flutter_tools/src/base/context.dart:95:20)
#10     AppContext.get (package:flutter_tools/src/base/context.dart:124:32)
#11     analytics (package:flutter_tools/src/globals.dart:98:36)
#12     _handleToolError (package:flutter_tools/runner.dart:190:13)
#13     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:142:13)
#14     _rootRunBinary (dart:async/zone.dart:1423:47)
#15     _CustomZone.runBinary (dart:async/zone.dart:1315:19)
#16     runZonedGuarded.<anonymous closure> (dart:async/zone.dart:1798:18)
#17     _Zone._processUncaughtError (dart:async/zone.dart:1081:14)
#18     _CustomZone.handleUncaughtError (dart:async/zone.dart:1285:5)
#19     Future._propagateToListeners (dart:async/future_impl.dart:797:16)
#20     Future._completeError (dart:async/future_impl.dart:660:5)
#21     Future._asyncCompleteError.<anonymous closure> (dart:async/future_impl.dart:746:7)
#22     _rootRun (dart:async/zone.dart:1399:13)
#23     _CustomZone.run (dart:async/zone.dart:1301:19)
#24     _CustomZone.runGuarded (dart:async/zone.dart:1209:7)
#25     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1249:23)
#26     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#27     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#28     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#29     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)
@eliasyishak
Copy link
Contributor

Hey @dcharkes, thanks for sharing! Would you mind sharing if this happens every time or flakey?

@dcharkes
Copy link
Contributor Author

Every time, I'm not even able to make a clean checkout at the moment:

"/Users/dacoharkes/flt/engine/src/third_party/dart/tools/sdks/dart-sdk/bin/dart pub get --offline" failed in "/Users/dacoharkes/flt/engine/src/flutter/ci" with status 255:
b"An unexpected error was encountered by the Dart CLI.\nPlease file an issue at https://github.com/dart-lang/sdk/issues/new with the following details:\n\nInvocation: 'dart pub get --offline'\nException: 'type 'Null' is not a subtype of type 'int' in type cast'\nStack Trace:\n#0      Session._refreshSessionData.parseContents (package:unified_analytics/src/session.dart:85:43)\n#1      Session._refreshSessionData (package:unified_analytics/src/session.dart:89:7)\n#2      new Session (package:unified_analytics/src/session.dart:28:5)\n#3      new AnalyticsImpl (package:unified_analytics/src/analytics.dart:421:23)\n#4      new Analytics (package:unified_analytics/src/analytics.dart:83:12)\n#5      createUnifiedAnalytics (package:dartdev/src/unified_analytics.dart:23:10)\n#6      DartdevRunner.runCommand (package:dartdev/dartdev.dart:177:27)\n#7      CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:122:25)\n#8      new Future.sync (dart:async/future.dart:306:31)\n#9      CommandRunner.run (package:args/command_runner.dart:122:14)\n#10     runDartdev (package:dartdev/dartdev.dart:58:29)\n#11     main (file:///Volumes/Work/s/w/ir/x/w/sdk/pkg/dartdev/bin/dartdev.dart:11:9)\n#12     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:293:33)\n#13     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)\n\n"

The problematic dart version:

dacoharkes-macbookpro2:build-hhh dacoharkes$ /Users/dacoharkes/flt/engine/src/third_party/dart/tools/sdks/dart-sdk/bin/dart --version
Dart SDK version: 3.4.0-108.0.dev (dev) (Mon Feb 5 00:03:28 2024 -0800) on "macos_arm64"

@eliasyishak
Copy link
Contributor

eliasyishak commented Mar 14, 2024

Thanks for the detailed info.. chatted a bit offline about this but to clear up the error, this is likely due to a version update in package:unified_analytics that changed the file for the session file.

{"session_id": 123, "last_ping": 124} // old

{"session_id": 123} // new

This change was made in a previous PR aimed at reducing how many times we write to disk.

So if you end up upgrading the flutter-tool (or another client of package:unified_analytics) to a version that changes this json file to the new format.... and then later you change the flutter-tool version to an older version, you will run into this error since it will try to look up last_ping in the json but it will fail to find it, causing a type error

Workaround: delete the session json file and it will trigger error handling in the package to recreate it as expected rm ~/.dart-tool/dart-flutter-telemetry-session.json

@davidmorgan
Copy link

davidmorgan commented Mar 18, 2024

Getting this one too.

I think this catch

      parseContents();
    } on FormatException catch (err) {

should be more generous: parsing can fail in other ways than FormatException.

Or, equivalently, make parseContents do a try+catch internally and rethrow anything as a FormatException, that's a bit nicer.

Then this will work as intended for future changes, recreating the data when the format changes :)

@mit-mit
Copy link
Member

mit-mit commented Mar 18, 2024

For anyone seeing this issue, please see the note at the top of dart-lang/sdk#55212

copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Mar 18, 2024
To pick up the fixes for dart-lang/tools#252

Change-Id: Ib0d5b8810d8c785df1e3990f3428df8dc4834297
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358220
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
@christopherfujino
Copy link
Member

To summarize the state of the world:

  1. The patched good version of unified_analytics is v5.8.8
  2. the Flutter CLI tool has this version rolled at HEAD as of March 15: flutter/flutter@8d54abf
  3. the Dart SDK (and thus any dart tooling maintained in dart-lang/sdk) picked up this change at HEAD as of March 18 dart-lang/sdk@87473f8
  4. This Dart SDK revision rolled to flutter/engine on March 18 in Roll Dart SDK from f874a4976038 to 3e64b8fcbfb7 (1 revision) flutter/engine#51509
  5. This engine revision rolled to flutter/flutter on March 18: flutter/flutter@ca864c0

Thus, at the HEAD of the master channel for the Flutter SDK, this issue should be fixed, save for any tools that are maintained outside of flutter/flutter or dart-lang/sdk.

@mit-mit
Copy link
Member

mit-mit commented Mar 20, 2024

@christopherfujino with that, can we resolve this issue, or are there more changes needed?

@christopherfujino
Copy link
Member

@christopherfujino with that, can we resolve this issue, or are there more changes needed?

Let me take a look right now, see if there are any loose ends I missed, and then I will close.

@christopherfujino
Copy link
Member

@christopherfujino with that, can we resolve this issue, or are there more changes needed?

Yes, it looks like Flutter developers should no longer be affected by this on the master channel, and Dart developers on the dev channel.

@christopherfujino
Copy link
Member

Also, the latest beta release of Flutter appears to predate the regression (https://github.com/flutter/flutter/blob/beta/packages/flutter_tools/pubspec.yaml#L54)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

5 participants