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

Joplin crashed on Android #8047

Closed
simonla opened this issue Apr 12, 2023 · 4 comments
Closed

Joplin crashed on Android #8047

simonla opened this issue Apr 12, 2023 · 4 comments
Labels
bug It's a bug mobile All mobile platforms stale An issue that hasn't been active for a while...

Comments

@simonla
Copy link

simonla commented Apr 12, 2023

Environment

Joplin version: 2.11.2
Platform: Android
OS specifics: Android 13

Steps to reproduce

  1. Attach a ~50MB file
  2. Sync to S3

Logfile

04-13 02:55:08.106 31284 31344 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
04-13 02:55:08.106 31284 31344 E AndroidRuntime: Process: net.cozic.joplin, PID: 31284
04-13 02:55:08.106 31284 31344 E AndroidRuntime: java.lang.RuntimeException: Could not invoke RNFSManager.readFile
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at com.facebook.jni.NativeRunnable.run(Native Method)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:942)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at android.os.Looper.loopOnce(Looper.java:210)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:299)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:1012)
04-13 02:55:08.106 31284 31344 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        ... 9 more
04-13 02:55:08.106 31284 31344 E AndroidRuntime: Caused by: java.lang.OutOfMemoryError: Failed to allocate a 67339208 byte allocation with 9747504 free bytes and 9519KB until OOM, target footprint 268435456, growth limit 268435456
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at java.lang.StringFactory.newStringFromChars(StringFactory.java:112)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at java.lang.StringFactory.newStringFromBytes(StringFactory.java:97)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at java.lang.StringFactory.newStringFromBytes(StringFactory.java:65)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at android.util.Base64.encodeToString(Base64.java:458)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        at com.rnfs.RNFSManager.readFile(RNFSManager.java:227)
04-13 02:55:08.106 31284 31344 E AndroidRuntime:        ... 11 more

OutOfMemory On Base64.encodeToString

  @ReactMethod
  public void readFile(String filepath, Promise promise) {
    try {
      InputStream inputStream = getInputStream(filepath);
      byte[] inputData = getInputStreamBytes(inputStream);
      String base64Content = Base64.encodeToString(inputData, Base64.NO_WRAP);

      promise.resolve(base64Content);
    } catch (Exception ex) {
      ex.printStackTrace();
      reject(promise, filepath, ex);
    }
  }

Does anyone know where will invoke readFile on JS side? @laurent22

I'm interested in fixing this

@simonla simonla added the bug It's a bug label Apr 12, 2023
@laurent22 laurent22 added mobile All mobile platforms high High priority issues labels Apr 12, 2023
@laurent22
Copy link
Owner

Not sure where exactly so you'll need to trace the code. Ideally we'd move away from that rnblob library but not sure if there's a good alternative

@simonla
Copy link
Author

simonla commented Apr 17, 2023

Current situation:

In the implementation of S3 file synchronization, We use RNFS to read file into JavaScript at once, which causing Java OOM.

Possible solutions:

  1. Read and upload file in chunks. The advantage is that it requires minimal changes and is less likely to cause problems, but the disadvantage is the cost of memory copying and Base64 serialization.
  2. Use uploadBlob to upload file. The advantage is that it does not copy the original file data, so the speed will be faster.

@laurent22 laurent22 removed the high High priority issues label Sep 24, 2023
@github-actions
Copy link
Contributor

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? If you require support or are requesting an enhancement or feature then please create a topic on the Joplin forum. This issue may be closed if no further activity occurs. You may comment on the issue and I will leave it open. Thank you for your contributions.

@github-actions github-actions bot added the stale An issue that hasn't been active for a while... label Oct 25, 2023
Copy link
Contributor

github-actions bot commented Nov 2, 2023

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, feel free to create a new issue with up-to-date information.

@github-actions github-actions bot closed this as completed Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It's a bug mobile All mobile platforms stale An issue that hasn't been active for a while...
Projects
None yet
Development

No branches or pull requests

2 participants