apache / apache/cordova-android
issues with large sets of response payload, even in smaller chunks
- Dominant language
- JavaScript
- Stars
- 3.8k
- Forks
- 1.6k
- Avg merge
- 16h 18m
- Merged PRs (30d)
- 11
Description
# Bug Report
## Problem
I am working on a new plugin for a major customer, with some enhancements to support several hundred megabytes worth of response data. If I would send all of the data at once, the Java code would crash with a JSON memory error. The obvious workaround would be to send the response data in multiple parts, with multiple plugin responses as documented and supported by the API.
But if I would send too many plugin responses, it would still crash with a JSON memory error. I think the cause is that the MAX_PAYLOAD_SIZE value of 500 MB is way too large
[here](https://github.com/apache/cordova-android/blob/8.1.0/framework/src/org/apache/cordova/NativeToJsMessageQueue.java#L42).
I have made [`github:brodybits/cordova-big-android-response-payload-test`](https://github.com/brodybits/cordova-big-android-response-payload-test) as a demo which can be used to reproduce this issue. It will send the responses in 1 MB chunks, which should be no problem. It seems to work consistently stable with 20 native response chunks, memory issues with 400 native response chunks.
I tried reducing `MAX_PAYLOAD_SIZE` to 16 MB, and it does seem to resolve the crash. But if there are too many plugin responses, I would then see some ugly module warning messages like this:
```
2020-06-04 23:23:53.703 6741-6741/com.demoapp I/chromium: [INFO:CONSOLE(53)] "Uncaught module cordova/plugin/android/polling not found", source: file:///android_asset/www/cordova.js (53)
```
and if I don't use background threading, the JavaScript would not see all of the response messages.
A project colleague pointed to the some code which seems to trigger the module not found messages - [here](https://github.com/apache/cordova-android/blob/8.1.0/framework/src/org/apache/cordova/NativeToJsMessageQueue.java#L199).
Here is [the original thread on the mailing list](https://lists.apache.org/thread.html/ree03f1d05bea6d41171ab6f3f0d9a2406dba5f17ec11b2cdc043d0fa%40%3Cdev.cordova.apache.org%3E).
### What is expected to happen?
- sending large sets of response payload data chunks should just work without crashes and without module not found warning messages
### What does actually happen?
- sending large sets of response payload data, even in smaller chunks, leads to crashes, with both reproduction and analysis given above
- reducing MAX_PAYLOAD_SIZE as described above does seem to resolve the crash but seems to uncover some other issues as described above
## Information
see above
### Command or Code
see above
### Environment, Platform, Device
- cordova-android 8.1.0
- cordova-android from master with MAX_PAYLOAD_SIZE reduced to 16 MB
- device: Samsung Galaxy SM-G920V with Android version 7.0
### Version information
- cordova-android: 8.1.0 & master
- Cordova CLI: 9.0.0 (cordova-lib@9.0.1)
- Cordova plugin: test plugin which is part of the test project described above
- host: macOS Catalina
## Checklist
- [x] I searched for existing GitHub issues
- [x] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
Contributor guide
Research direction
Start with framework/src/org/apache/cordova/NativeToJsMessageQueue.java, especially MAX_PAYLOAD_SIZE and the code around line 199. Run the linked brodybits/cordova-big-android-response-payload-test demo with many 1 MB native response chunks on the reported Android setup. Done means large chunked responses avoid memory crashes, module-not-found warnings, and missing JavaScript messages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java, javascript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100