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

Android crash - Illegal callback invocation from native module - RuntimeException firing twice #113

Closed
scgough opened this issue Feb 2, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@scgough
Copy link

scgough commented Feb 2, 2022

I've been trying to get to the bottom of this issue. I've seen it over on the old repo and there's not been a good solution for it.

On certain devices...namely Realme, Oppo and Huawei a regular crash seems to be occurring. I've tested using a "Realme 7" phone, Android 11 and can reproduce it every time w/ the below scenario.

The issue seems to be triggered if you re-download a previously downloaded item again and you have addAndroidDownloads: path set.

Upon completing the 2nd download onReceive seems to fire twice.
The following line is called:

this.callback.invoke(null, ReactNativeBlobUtilConst.RNFB_RESPONSE_PATH, customDest);

At this point in time this.callback.mInvoked is true which fires an exception taking you to line 808 which attempts to fire another callback and causes the crash:

this.callback.invoke(ex.getLocalizedMessage(), null);

I can get this issue to stop happening if I change the path supplied to be unique so I'm wondering if this is something to do with this value or maybe the source file Url?

I'd love to figure out exactly why this is happening! Has anyone else seen this?

@RonRadtke
Copy link
Owner

The problem is actually that it is called twice. Since react-native is not allowing the fire the callback twice.
Most likely this is caused by the device triggering multiple DownloadManager.ACTION_DOWNLOAD_COMPLETE
Probably you could even see these events in logcat.

I assume it's related to this bug here: https://issuetracker.google.com/issues/36930682#c13

The problem arises with fixing this issue. Probably we could implement a flag making sure the method is only called once - or just trying to catch the RuntimeException thrown by ract-native

@scgough
Copy link
Author

scgough commented Feb 4, 2022

Wow that is an old issue then... 😄

Thanks for looking into this. The unique path value "fix" I've used seems to have helped a lot but something more solid like you mentioned would be cool sort out too.

@RonRadtke RonRadtke self-assigned this Feb 4, 2022
@RonRadtke RonRadtke added the bug Something isn't working label Feb 4, 2022
@RonRadtke RonRadtke changed the title Android crash - Illegal callback invocation from native module Android crash - Illegal callback invocation from native module - RuntimeException firing twice Feb 4, 2022
@Saad-Bashar
Copy link

Not sure if I have the similar problem, #164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants