Reduce default max message size to 4 MiB

Fixes #1676
This commit is contained in:
Eric Anderson 2016-06-30 16:27:29 -07:00
parent 2d7347fbfc
commit 16b096b571
9 changed files with 30 additions and 11 deletions

View File

@ -131,9 +131,9 @@ public final class GrpcUtil {
public static final String MESSAGE_ACCEPT_ENCODING = "grpc-accept-encoding";
/**
* The default maximum uncompressed size (in bytes) for inbound messages. Defaults to 100 MiB.
* The default maximum uncompressed size (in bytes) for inbound messages. Defaults to 4 MiB.
*/
public static final int DEFAULT_MAX_MESSAGE_SIZE = 100 * 1024 * 1024;
public static final int DEFAULT_MAX_MESSAGE_SIZE = 4 * 1024 * 1024;
/**
* The default maximum size (in bytes) for inbound header/trailer.

View File

@ -333,7 +333,8 @@ public class MessageDeframer implements Closeable {
// Update the required length to include the length of the frame.
requiredLength = nextFrame.readInt();
if (requiredLength < 0 || requiredLength > maxMessageSize) {
throw Status.INTERNAL.withDescription(String.format("Frame size %d exceeds maximum: %d, ",
throw Status.INTERNAL.withDescription(String.format("Frame size %d exceeds maximum: %d. "
+ "If this is normal, increase the maxMessageSize in the channel/server builder",
requiredLength, maxMessageSize)).asRuntimeException();
}
@ -440,7 +441,8 @@ public class MessageDeframer implements Closeable {
private void verifySize() {
if (count > maxMessageSize) {
throw Status.INTERNAL.withDescription(String.format(
"Compressed frame exceeds maximum frame size: %d. Bytes read: %d",
"Compressed frame exceeds maximum frame size: %d. Bytes read: %d. "
+ "If this is normal, increase the maxMessageSize in the channel/server builder",
maxMessageSize, count)).asRuntimeException();
}
}

View File

@ -57,6 +57,7 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest {
NettyServerBuilder
.forAddress(new LocalAddress("in-process-1"))
.flowControlWindow(65 * 1024)
.maxMessageSize(16 * 1024 * 1024)
.channelType(LocalServerChannel.class));
}
@ -72,6 +73,8 @@ public class Http2NettyLocalChannelTest extends AbstractInteropTest {
.forAddress(new LocalAddress("in-process-1"))
.negotiationType(NegotiationType.PLAINTEXT)
.channelType(LocalChannel.class)
.flowControlWindow(65 * 1024)
.maxMessageSize(16 * 1024 * 1024)
.build();
}
}

View File

@ -60,6 +60,7 @@ public class Http2NettyTest extends AbstractInteropTest {
try {
startStaticServer(NettyServerBuilder.forPort(0)
.flowControlWindow(65 * 1024)
.maxMessageSize(16 * 1024 * 1024)
.sslContext(GrpcSslContexts
.forServer(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"))
.clientAuth(ClientAuth.REQUIRE)
@ -82,6 +83,8 @@ public class Http2NettyTest extends AbstractInteropTest {
try {
return NettyChannelBuilder
.forAddress(TestUtils.testServerAddress(getPort()))
.flowControlWindow(65 * 1024)
.maxMessageSize(16 * 1024 * 1024)
.sslContext(GrpcSslContexts
.forClient()
.keyManager(TestUtils.loadCert("client.pem"), TestUtils.loadCert("client.key"))

View File

@ -85,6 +85,8 @@ public class Http2OkHttpTest extends AbstractInteropTest {
GrpcSslContexts.configure(contextBuilder, sslProvider);
contextBuilder.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE);
startStaticServer(NettyServerBuilder.forPort(0)
.flowControlWindow(65 * 1024)
.maxMessageSize(16 * 1024 * 1024)
.sslContext(contextBuilder.build()));
} catch (IOException ex) {
throw new RuntimeException(ex);
@ -99,6 +101,7 @@ public class Http2OkHttpTest extends AbstractInteropTest {
@Override
protected ManagedChannel createChannel() {
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("127.0.0.1", getPort())
.maxMessageSize(16 * 1024 * 1024)
.connectionSpec(new ConnectionSpec.Builder(OkHttpChannelBuilder.DEFAULT_CONNECTION_SPEC)
.cipherSuites(TestUtils.preferredTestCiphers().toArray(new String[0]))
.tlsVersions(ConnectionSpec.MODERN_TLS.tlsVersions().toArray(new TlsVersion[0]))

View File

@ -46,15 +46,15 @@ import io.grpc.DecompressorRegistry;
import io.grpc.ForwardingClientCall;
import io.grpc.ForwardingClientCallListener;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.ServerBuilder;
import io.grpc.ServerCall;
import io.grpc.ServerCall.Listener;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import io.grpc.internal.GrpcUtil;
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.NettyServerBuilder;
import io.grpc.testing.integration.Messages.CompressionType;
import io.grpc.testing.integration.Messages.Payload;
import io.grpc.testing.integration.Messages.PayloadType;
@ -101,7 +101,8 @@ public class TransportCompressionTest extends AbstractInteropTest {
compressors.register(FZIPPER);
compressors.register(Codec.Identity.NONE);
startStaticServer(
ServerBuilder.forPort(0)
NettyServerBuilder.forPort(0)
.maxMessageSize(16 * 1024 * 1024)
.compressorRegistry(compressors)
.decompressorRegistry(decompressors),
new ServerInterceptor() {
@ -147,7 +148,8 @@ public class TransportCompressionTest extends AbstractInteropTest {
@Override
protected ManagedChannel createChannel() {
return ManagedChannelBuilder.forAddress("localhost", getPort())
return NettyChannelBuilder.forAddress("localhost", getPort())
.maxMessageSize(16 * 1024 * 1024)
.decompressorRegistry(decompressors)
.compressorRegistry(compressors)
.intercept(new ClientInterceptor() {

View File

@ -191,7 +191,9 @@ public class NettyChannelBuilder extends AbstractManagedChannelImplBuilder<Netty
/**
* Sets the maximum message size allowed to be received on the channel. If not called,
* defaults to {@link GrpcUtil#DEFAULT_MAX_MESSAGE_SIZE}.
* defaults to 4 MiB. The default provides protection to clients who haven't considered the
* possibility of receiving large messages while trying to be large enough to not be hit in normal
* usage.
*/
public final NettyChannelBuilder maxMessageSize(int maxMessageSize) {
checkArgument(maxMessageSize >= 0, "maxMessageSize must be >= 0");

View File

@ -203,7 +203,9 @@ public final class NettyServerBuilder extends AbstractServerImplBuilder<NettySer
/**
* Sets the maximum message size allowed to be received on the server. If not called,
* defaults to 100 MiB.
* defaults to 4 MiB. The default provides protection to services who haven't considered the
* possibility of receiving large messages while trying to be large enough to not be hit in normal
* usage.
*/
public NettyServerBuilder maxMessageSize(int maxMessageSize) {
checkArgument(maxMessageSize >= 0, "maxMessageSize must be >= 0");

View File

@ -181,7 +181,9 @@ public class OkHttpChannelBuilder extends
/**
* Sets the maximum message size allowed to be received on the channel. If not called,
* defaults to {@link io.grpc.internal.GrpcUtil#DEFAULT_MAX_MESSAGE_SIZE}.
* defaults to 4 MiB. The default provides protection to clients who haven't considered the
* possibility of receiving large messages while trying to be large enough to not be hit in normal
* usage.
*/
public final OkHttpChannelBuilder maxMessageSize(int maxMessageSize) {
checkArgument(maxMessageSize >= 0, "maxMessageSize must be >= 0");