flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

[Health version: 3.0.5] crash in SwiftHealthPlugin.getData

Open avto-region opened this issue 3 years ago • 5 comments

Device / Emulator and OS

  • Device: [any iOS device]
  • OS: [iOS]

Describe the bug

We get numerous crashes for iOS users after migrating to Health package. Although we cannot find a way to reproduce the crash the issue still persists.

To Reproduce

The issue is not reproducible

Expected behavior

User can interact with the package without getting any crashes

Actual behavior

When we call the method to get new data to update the ui, sometimes the users get a following crash:

Crashed: com.apple.HealthKit.HKHealthStore.client.0x283b15c80 0 health 0x102da4edc closure #2 in closure #1 in SwiftHealthPlugin.getData(call:result:) + 168 (:168) 1 health 0x102dabb0c partial apply for closure #1 in SwiftHealthPlugin.getData(call:result:) + 112 (SwiftHealthPlugin.swift:112) 2 health 0x102da533c thunk for @escaping @callee_guaranteed (@guaranteed HKSampleQuery, @guaranteed [HKSample]?, @guaranteed Error?) -> () + 116 (:116) 3 libdispatch.dylib 0x1a459da84 _dispatch_call_block_and_release + 32 4 libdispatch.dylib 0x1a459f81c _dispatch_client_callout + 20 5 libdispatch.dylib 0x1a45a7004 _dispatch_lane_serial_drain + 620 6 libdispatch.dylib 0x1a45a7c34 _dispatch_lane_invoke + 456 7 libdispatch.dylib 0x1a45b24bc _dispatch_workloop_worker_thread + 764 8 libsystem_pthread.dylib 0x1f05167a4 _pthread_wqthread + 276 9 libsystem_pthread.dylib 0x1f051d74c start_wqthread + 8

Flutter doctor

[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5 20G71 darwin-x64, locale en-DE) • Flutter version 2.2.3 at /Users/igor/Development/flutter • Framework revision f4abaa0735 (4 weeks ago), 2021-07-01 12:46:11 -0700 • Engine revision 241c87ad80 • Dart version 2.13.4

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/***/Library/Android/sdk • Platform android-30, build-tools 30.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) ✗ Android license status unknown. Run flutter doctor --android-licenses to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.5.1, Build version 12E507 • CocoaPods version 1.10.1

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.58.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0

[✓] Connected device (3 available) • iPhone (***) (mobile) • 00008020-001438CE0AFA002E • ios • iOS 14.6 • iPhone 11 (mobile) • BF533310-3BC3-496D-BDB9-D33C2C77D37D • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator) • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.107

avto-region avatar Jul 26 '21 13:07 avto-region

I've had the same on health 3.1.1+1. It happened in production - I was not able to reproduce it myself.

noinskit avatar Sep 23 '21 13:09 noinskit

The HKSampleQuery in question was actually running on a worker thread, but the Flutter plugin channel method was calling on the main thread. According to the official Flutter documentation here, the result is therefore required to be returned on the UI main thread only.

matsunanaro avatar Oct 13 '21 10:10 matsunanaro

Was this issue ever resolved???

Am getting the same crash multiple times on 3.4.4

rsbthebest avatar Mar 24 '22 06:03 rsbthebest

This issue is still impacting iOS users - frequency of fatal crashes has picked up in 3.4.4

Hard to reproduce, but when it happens, there's an error here: image

W2YAdmin avatar Mar 24 '22 13:03 W2YAdmin

also had these a couple of times (4.0.0). Anyone tried to handle this on their own?

fix92 avatar Jul 13 '22 07:07 fix92