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

[BUG] [iOS] Unserializable objects in downloadFile call argument cause download failing #2281

Open
AceOfWands opened this issue Dec 14, 2024 · 1 comment

Comments

@AceOfWands
Copy link

Bug Report

Plugin(s)

  • @capacitor/filesystem: 6.0.2

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 6.2.0
  @capacitor/core: 6.2.0
  @capacitor/android: 6.2.0
  @capacitor/ios: 6.2.0

Installed Dependencies:

  @capacitor/cli: 6.1.2
  @capacitor/core: 6.1.2
  @capacitor/android: 6.1.2
  @capacitor/ios: 6.1.2

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

  • iOS

Current Behavior

When running the app on iOS, adding a webFetchExtra property containing an abort controller signal to the argument passed to the downloadFile method causes a DataCloneError exception to be thrown, resulting in the download failing.

Here is the problematic code snippet:

await Filesystem.downloadFile({
  path: path,
  url: downloadUrl,
  directory: directory,
  progress: true,
  webFetchExtra: { signal },
  readTimeout: 7000,
});

Expected Behavior

The downloadFile method should not throw a DataCloneError. Either:

  • The argument passed to the downloadFile method should be fully serialized before being pushed to the web worker, or
  • The webFetchExtra property should be removed entirely before the data is sent to native platforms if it's not used there.

Code Reproduction

Reproduce the issue by using the following code:

const controller = new AbortController();
const signal = controller.signal;
await Filesystem.downloadFile({
  path: "Download/logo.png",
  url: "https://upload.wikimedia.org/wikipedia/commons/thumb/8/80/Wikipedia-logo-v2.svg/1200px-Wikipedia-logo-v2.svg.png",
  directory: Directory.ExternalStorage,
  webFetchExtra: { signal }
});

Other Technical Details

  • Error: DataCloneError
  • Cause: The signal object is not serializable but is still pushed to the web worker.
  • Notes: The error occurs because signal (part of AbortController) cannot be cloned or serialized for transfer between threads.

Additional Context

The downloadFile argument must either be fully serialized or have its webFetchExtra property stripped out before being sent to the native layer.

@Ionitron
Copy link
Collaborator

This issue needs more information before it can be addressed.
In particular, the reporter needs to provide a minimal sample app that demonstrates the issue.
If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks!
Ionitron 💙

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

No branches or pull requests

3 participants