miguelpruivo/flutter_file_picker

[iOS] File picker crashes when accidentally picking a file across async gap

Closed this issue · 6 comments

Describe the bug
On iOS, file picker will crash if you pick a video file that takes some time to process (ie. .MOV video file), then start the file picker again. In my case, I protect against re-picking a file in a single screen (via state), however, if the user exits the screen and comes back and picks a file again all while the first file is processing the crash will still happen.

Platform

  • Android
  • iOS
  • Web
  • Desktop

Platform OS version
iOS 17 but also repro on iOS 16

How are you picking?

FilePickerResult? result = await FilePicker.platform.pickFiles(
    type: FileType.video,
    onFileLoading: (status) => setState(() {
          _status = status;
        }));

if (result != null &&
    result.isSinglePick &&
    result.files.single.path != null) {
  videoFile = File(result.files.single.path!);
}

Details to reproduce the issue

  • Have 2 screens, screen1 opens up screen2.
  • Screen 2 has a file picker
  • Pick a file on screen 2 but choose a large file that the OS may take a long time to load. In my case, I can easily reproduce with a 100MB+ .MOV file which iOS seems to do some processing on after being picked
  • After choosing the file, exit screen 2, then come back to screen 2 and pick a file again
  • File picker throws error multiple_request which can be successfully caught and shown as an error
  • However, shortly after, the first file completes processing and then crashes the app completely - there does not appear to be a way to catch this error

Error Log
Flutter shows:

The 'miguelruivo.flutter.plugins.filepickerevent' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.

I'm not that good at capturing iOS native crashes, but I believe it's the same crashes reported in these issues which have more logging:
#1205
#1112
#927

Screenshots and/or video
If applicable, add screenshots or video to help explain your problem.

Flutter Version details

adam:~/ $ flutter doctor -v                                                    [14:27:58]
[✓] Flutter (Channel stable, 3.13.9, on macOS 14.1 23B74 darwin-arm64, locale en-AU)
    • Flutter version 3.13.9 on channel stable at /Users/adam/lib/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (3 weeks ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/adam/lib/android-sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/adam/lib/android-sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.13.0

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

[✓] Android Studio (version 2022.3)
    • 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 17.0.6+0-17.0.6b829.9-10027231)

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

[✓] Connected device (3 available)
    • iPhone 15 Pro (mobile) • 4903CDBE-EBE3-467D-B36E-8C23B96EB576 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   •
      macOS 14.1 23B74 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript •
      Google Chrome 119.0.6045.123

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Additional context
I am able to repro this 100%, please let me know what other info you need.

Same issue, I try to add another file when the first file is loading, and it will make a crash

This issue is stale because it has been open for 14 days with no activity.

Still able to repro

This issue is stale because it has been open for 14 days with no activity.

This issue was closed because it has been inactive for 14 days since being marked as stale.

Still able to repro