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

React Native Android thread crashes in production (java.util.concurrent.RejectedExecutionException) #397

Closed
davidshariff opened this issue Apr 15, 2022 · 10 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request fixed-in-react-native-v4.5.2 react-native Affect react-native platform v4.5.1 Affects v4.5.1 release

Comments

@davidshariff
Copy link

Description
When running FFmpegKit.execute or FFmpegKit.executeWithArguments on React Native Android, the app crashes abruptly in com.arthenica.ffmpegkit.reactnative.FFmpegKitReactNativeModule.ffmpegSessionExecute throwing java.util.concurrent.RejectedExecutionException.

Expected behavior
Should resolve with the FFMPEG output or throw an error.

Current behavior
Crashes the app.

To Reproduce
I'm currently running the following command:

FFmpegKit.executeWithArguments([
    '-i', uri,
    '-ac', '1',
    '-vn',
    '-c:a', 'flac',
    outputFilePath
])

Screenshots
Devices having issues:
Screen Shot 2022-04-15 at 2 28 25 PM

Logs

java.util.concurrent.RejectedExecutionException: 
  at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution (ThreadPoolExecutor.java:2086)
  at java.util.concurrent.ThreadPoolExecutor.reject (ThreadPoolExecutor.java:848)
  at java.util.concurrent.ThreadPoolExecutor.execute (ThreadPoolExecutor.java:1394)
  at java.util.concurrent.AbstractExecutorService.submit (AbstractExecutorService.java:118)
  at com.arthenica.ffmpegkit.reactnative.FFmpegKitReactNativeModule.ffmpegSessionExecute (FFmpegKitReactNativeModule.java:595)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
  at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:151)
  at com.facebook.react.bridge.queue.NativeRunnable.run (Native Method)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:27)
  at android.os.Looper.loop (Looper.java:246)
  at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:226)
  at java.lang.Thread.run (Thread.java:923)

Environment

  • Platform: ReactNative Android
  • Architecture: arm64-v8a, armeabi-v7a, armeabi
  • Version: v4.5.1.full-gpl-lts
  • Source branch: main
  • react-native info: React: 16.13.1, ffmpeg-kit-react-native: 4.5.1
@tanersener tanersener added needs-analysis We don't know that this is. It must be investigated further react-native Affect react-native platform v4.5.1 Affects v4.5.1 release labels Apr 15, 2022
@tanersener
Copy link
Collaborator

Is this issue reproducible? I don't see a clear explanation in the stack trace about why the execution is rejected.

@mars-lan
Copy link

Additional info in my case:

Fatal Exception: java.util.concurrent.RejectedExecutionException
Task java.util.concurrent.FutureTask@72f1039 rejected from java.util.concurrent.ThreadPoolExecutor@b11767e[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]

Seems like the executor has been shutdown already? https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html

@tanersener
Copy link
Collaborator

@mars-lan Thanks. Is this behaviour reproducible?

@mars-lan
Copy link

mars-lan commented May 17, 2022

@tanersener unfortunately it's kind of random and not readily reproducible. However, it's frequent enough that it's one of the top crashing issues on our Crashlytics.

@tanersener
Copy link
Collaborator

We don't see it in the test apps. So, hard to make a comment about it.

@mars-lan
Copy link

I found the root cause and was able to reproduce it.

This line shuts down the executor when the main activity is destroyed. In many cases, the application process will also be killed so the cleanup is justified. However, if the application has any other services running, e.g. a foreground service, the process won't be killed. As a result, the executor won't be recreated when the main activity is launched again, thus leading to the submission of tasks to a terminated executor.

@tanersener
Copy link
Collaborator

Thanks for the analysis. Let me check the lifecycle documentation to verify your theory.

@tanersener
Copy link
Collaborator

I removed that line in the new v4.5.2 release we have for react-native. It should be fixed now.

@davidshariff
Copy link
Author

I updated v4.5.2 to production, looks like the bug is confirmed fixed.

@tanersener I think we can resolve this issue now. Thank you.

@tanersener
Copy link
Collaborator

@davidshariff Great, thanks!

@tanersener tanersener added bug Something isn't working enhancement New feature or request fixed-in-react-native-v4.5.2 and removed needs-analysis We don't know that this is. It must be investigated further labels May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request fixed-in-react-native-v4.5.2 react-native Affect react-native platform v4.5.1 Affects v4.5.1 release
Projects
None yet
Development

No branches or pull requests

3 participants