Skip to content

Commit

Permalink
Lower Limit for Maximum Message Size in TcpTransport (#44496) (#45635)
Browse files Browse the repository at this point in the history
* Since we're buffering network reads to the heap and then deserializing them it makes no sense to buffer a message that is 90% of the heap size since we couldn't deserialize it anyway
* I think `30%` is a more reasonable guess here given that we can reasonably assume that the deserialized message will be larger than the serialized message itself and processing it will take additional heap as well
  • Loading branch information
original-brownbear authored Aug 16, 2019
1 parent da03a5d commit d6a9ede
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements

// This is the number of bytes necessary to read the message size
private static final int BYTES_NEEDED_FOR_MESSAGE_SIZE = TcpHeader.MARKER_BYTES_SIZE + TcpHeader.MESSAGE_LENGTH_SIZE;
private static final long NINETY_PER_HEAP_SIZE = (long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.9);
private static final long THIRTY_PER_HEAP_SIZE = (long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.3);
private static final BytesReference EMPTY_BYTES_REFERENCE = new BytesArray(new byte[0]);

// this limit is per-address
Expand Down Expand Up @@ -755,9 +755,9 @@ private static int readHeaderBuffer(BytesReference headerBuffer) throws IOExcept
throw new StreamCorruptedException("invalid data length: " + messageLength);
}

if (messageLength > NINETY_PER_HEAP_SIZE) {
if (messageLength > THIRTY_PER_HEAP_SIZE) {
throw new IllegalArgumentException("transport content length received [" + new ByteSizeValue(messageLength) + "] exceeded ["
+ new ByteSizeValue(NINETY_PER_HEAP_SIZE) + "]");
+ new ByteSizeValue(THIRTY_PER_HEAP_SIZE) + "]");
}

return messageLength;
Expand Down

0 comments on commit d6a9ede

Please sign in to comment.