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

breaking: reduce combined response cutoff to 16 MB #987

Merged
merged 4 commits into from
Jun 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions framework/src/org/apache/cordova/NativeToJsMessageQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ public class NativeToJsMessageQueue {
// exec() is asynchronous. Set this to true when running bridge benchmarks.
static final boolean DISABLE_EXEC_CHAINING = false;

// Arbitrarily chosen upper limit for how much data to send to JS in one shot.
// This currently only chops up on message boundaries. It may be useful
// to allow it to break up messages.
private static int MAX_PAYLOAD_SIZE = 50 * 1024 * 10240;
// A hopefully reasonable upper limit of how much combined payload data
// to send to the JavaScript in one shot.
// This currently only chops up on message boundaries.
// It may be useful to split and reassemble response messages someday.
private static int COMBINED_RESPONSE_CUTOFF = 16 * 1024 * 1024;

/**
* When true, the active listener is not fired upon enqueue. When set to false,
Expand Down Expand Up @@ -124,7 +125,10 @@ private void packMessage(JsMessage message, StringBuilder sb) {

/**
* Combines and returns queued messages combined into a single string.
* Combines as many messages as possible, while staying under MAX_PAYLOAD_SIZE.
*
* Combines as many messages as possible, without exceeding
* COMBINED_RESPONSE_CUTOFF in case of multiple response messages.
*
* Returns null if the queue is empty.
*/
public String popAndEncode(boolean fromOnlineEvent) {
Expand All @@ -140,7 +144,10 @@ public String popAndEncode(boolean fromOnlineEvent) {
int numMessagesToSend = 0;
for (JsMessage message : queue) {
int messageSize = calculatePackedMessageLength(message);
if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0) {
if (numMessagesToSend > 0 &&
COMBINED_RESPONSE_CUTOFF > 0 &&
totalPayloadLen + messageSize > COMBINED_RESPONSE_CUTOFF
) {
break;
}
totalPayloadLen += messageSize;
Expand Down Expand Up @@ -175,7 +182,10 @@ public String popAndEncodeAsJs() {
int numMessagesToSend = 0;
for (JsMessage message : queue) {
int messageSize = message.calculateEncodedLength() + 50; // overestimate.
if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0) {
if (numMessagesToSend > 0 &&
COMBINED_RESPONSE_CUTOFF > 0 &&
totalPayloadLen + messageSize > COMBINED_RESPONSE_CUTOFF
) {
break;
}
totalPayloadLen += messageSize;
Expand Down