mirror of https://github.com/grpc/grpc-node.git
Fix default max message length values
This commit is contained in:
parent
9221fdea24
commit
4bb965d2d8
|
@ -40,3 +40,9 @@ export enum LogVerbosity {
|
||||||
INFO,
|
INFO,
|
||||||
ERROR,
|
ERROR,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -1 means unlimited
|
||||||
|
export const DEFAULT_MAX_SEND_MESSAGE_LENGTH = -1;
|
||||||
|
|
||||||
|
// 4 MB default
|
||||||
|
export const DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH = 4 * 1024 * 1024;
|
|
@ -17,15 +17,12 @@
|
||||||
|
|
||||||
import { BaseFilter, Filter, FilterFactory } from "./filter";
|
import { BaseFilter, Filter, FilterFactory } from "./filter";
|
||||||
import { Call, WriteObject } from "./call-stream";
|
import { Call, WriteObject } from "./call-stream";
|
||||||
import { Status } from "./constants";
|
import { Status, DEFAULT_MAX_SEND_MESSAGE_LENGTH, DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH } from "./constants";
|
||||||
import { ChannelOptions } from "./channel-options";
|
import { ChannelOptions } from "./channel-options";
|
||||||
|
|
||||||
// The default max message size for sending or receiving is 4 MB
|
|
||||||
const DEFAULT_MAX_MESSAGE_SIZE = 4 * 1024 * 1024;
|
|
||||||
|
|
||||||
export class MaxMessageSizeFilter extends BaseFilter implements Filter {
|
export class MaxMessageSizeFilter extends BaseFilter implements Filter {
|
||||||
private maxSendMessageSize: number = DEFAULT_MAX_MESSAGE_SIZE;
|
private maxSendMessageSize: number = DEFAULT_MAX_SEND_MESSAGE_LENGTH;
|
||||||
private maxReceiveMessageSize: number = DEFAULT_MAX_MESSAGE_SIZE;
|
private maxReceiveMessageSize: number = DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH;
|
||||||
constructor(
|
constructor(
|
||||||
private readonly options: ChannelOptions,
|
private readonly options: ChannelOptions,
|
||||||
private readonly callStream: Call
|
private readonly callStream: Call
|
||||||
|
|
|
@ -20,7 +20,7 @@ import * as http2 from 'http2';
|
||||||
import { Duplex, Readable, Writable } from 'stream';
|
import { Duplex, Readable, Writable } from 'stream';
|
||||||
|
|
||||||
import { StatusObject } from './call-stream';
|
import { StatusObject } from './call-stream';
|
||||||
import { Status } from './constants';
|
import { Status, DEFAULT_MAX_SEND_MESSAGE_LENGTH, DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH } from './constants';
|
||||||
import { Deserialize, Serialize } from './make-client';
|
import { Deserialize, Serialize } from './make-client';
|
||||||
import { Metadata } from './metadata';
|
import { Metadata } from './metadata';
|
||||||
import { StreamDecoder } from './stream-decoder';
|
import { StreamDecoder } from './stream-decoder';
|
||||||
|
@ -326,9 +326,6 @@ export type HandlerType = 'bidi' | 'clientStream' | 'serverStream' | 'unary';
|
||||||
|
|
||||||
const noopTimer: NodeJS.Timer = setTimeout(() => {}, 0);
|
const noopTimer: NodeJS.Timer = setTimeout(() => {}, 0);
|
||||||
|
|
||||||
// The default max message size for sending or receiving is 4 MB
|
|
||||||
const DEFAULT_MAX_MESSAGE_SIZE = 4 * 1024 * 1024;
|
|
||||||
|
|
||||||
// Internal class that wraps the HTTP2 request.
|
// Internal class that wraps the HTTP2 request.
|
||||||
export class Http2ServerCallStream<
|
export class Http2ServerCallStream<
|
||||||
RequestType,
|
RequestType,
|
||||||
|
@ -342,8 +339,8 @@ export class Http2ServerCallStream<
|
||||||
private isPushPending = false;
|
private isPushPending = false;
|
||||||
private bufferedMessages: Array<Buffer | null> = [];
|
private bufferedMessages: Array<Buffer | null> = [];
|
||||||
private messagesToPush: Array<RequestType | null> = [];
|
private messagesToPush: Array<RequestType | null> = [];
|
||||||
private maxSendMessageSize: number = DEFAULT_MAX_MESSAGE_SIZE;
|
private maxSendMessageSize: number = DEFAULT_MAX_SEND_MESSAGE_LENGTH;
|
||||||
private maxReceiveMessageSize: number = DEFAULT_MAX_MESSAGE_SIZE;
|
private maxReceiveMessageSize: number = DEFAULT_MAX_RECEIVE_MESSAGE_LENGTH;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private stream: http2.ServerHttp2Stream,
|
private stream: http2.ServerHttp2Stream,
|
||||||
|
|
|
@ -57,8 +57,12 @@ describe(`${anyGrpc.clientName} client -> ${anyGrpc.serverName} server`, functio
|
||||||
let client;
|
let client;
|
||||||
let port;
|
let port;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
/* The default server has no limits on max message size to make those
|
/* To make testing max message size enforcement easier, the we explicitly
|
||||||
* tests easier to write */
|
* remove the limit on the size of messages the server can receive, and
|
||||||
|
* we expect that the size of messages it can send is unlimited by
|
||||||
|
* default. On the other side, we explicitly limit the size of messages
|
||||||
|
* the client can send to 4 MB, and we expect that the size of messages
|
||||||
|
* it can receive is limited to 4 MB by default */
|
||||||
interopServer.getServer(0, true, (err, serverObj) => {
|
interopServer.getServer(0, true, (err, serverObj) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
done(err);
|
done(err);
|
||||||
|
@ -71,13 +75,13 @@ describe(`${anyGrpc.clientName} client -> ${anyGrpc.serverName} server`, functio
|
||||||
const creds = grpc.credentials.createSsl(ca_data);
|
const creds = grpc.credentials.createSsl(ca_data);
|
||||||
const options = {
|
const options = {
|
||||||
'grpc.ssl_target_name_override': 'foo.test.google.fr',
|
'grpc.ssl_target_name_override': 'foo.test.google.fr',
|
||||||
'grpc.default_authority': 'foo.test.google.fr'
|
'grpc.default_authority': 'foo.test.google.fr',
|
||||||
|
'grpc.max_send_message_length': 4*1024*1024
|
||||||
};
|
};
|
||||||
client = new testProto.TestService(`localhost:${port}`, creds, options);
|
client = new testProto.TestService(`localhost:${port}`, creds, options);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
'grpc.max_send_message_length': -1,
|
|
||||||
'grpc.max_receive_message_length': -1
|
'grpc.max_receive_message_length': -1
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -141,14 +145,12 @@ describe(`${anyGrpc.clientName} client -> ${anyGrpc.serverName} server`, functio
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe.only('max message size', function() {
|
describe.only('max message size', function() {
|
||||||
// Note: the main server has these checks disabled
|
|
||||||
// A size that is larger than the default limit
|
// A size that is larger than the default limit
|
||||||
const largeMessageSize = 32 * 1024 * 1024;
|
const largeMessageSize = 6 * 1024 * 1024;
|
||||||
const largeMessage = Buffer.alloc(largeMessageSize);
|
const largeMessage = Buffer.alloc(largeMessageSize);
|
||||||
it('should get an error when sending a large message', function(done) {
|
it('should get an error when sending a large message', function(done) {
|
||||||
done = multiDone(done, 2);
|
done = multiDone(done, 2);
|
||||||
const unaryMessage = {payload: {body: largeMessage}}
|
const unaryMessage = {payload: {body: largeMessage}};
|
||||||
console.log(client.unaryCall.requestSerialize(unaryMessage).length);
|
|
||||||
client.unaryCall(unaryMessage, (error, result) => {
|
client.unaryCall(unaryMessage, (error, result) => {
|
||||||
assert(error);
|
assert(error);
|
||||||
assert.strictEqual(error.code, grpc.status.RESOURCE_EXHAUSTED);
|
assert.strictEqual(error.code, grpc.status.RESOURCE_EXHAUSTED);
|
||||||
|
@ -228,7 +230,7 @@ describe(`${anyGrpc.clientName} client -> ${anyGrpc.serverName} server`, functio
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('with a server with message size limits', function() {
|
describe('with a server with message size limits and a client without limits', function() {
|
||||||
let restrictedServer;
|
let restrictedServer;
|
||||||
let restrictedServerClient;
|
let restrictedServerClient;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
|
@ -244,13 +246,12 @@ describe(`${anyGrpc.clientName} client -> ${anyGrpc.serverName} server`, functio
|
||||||
const options = {
|
const options = {
|
||||||
'grpc.ssl_target_name_override': 'foo.test.google.fr',
|
'grpc.ssl_target_name_override': 'foo.test.google.fr',
|
||||||
'grpc.default_authority': 'foo.test.google.fr',
|
'grpc.default_authority': 'foo.test.google.fr',
|
||||||
'grpc.max_send_message_length': -1,
|
|
||||||
'grpc.max_receive_message_length': -1
|
'grpc.max_receive_message_length': -1
|
||||||
};
|
};
|
||||||
restrictedServerClient = new testProto.TestService(`localhost:${serverObj.port}`, creds, options);
|
restrictedServerClient = new testProto.TestService(`localhost:${serverObj.port}`, creds, options);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
}, {'grpc.max_send_message_length': 4 * 1024 * 1024});
|
||||||
});
|
});
|
||||||
after(function() {
|
after(function() {
|
||||||
restrictedServer.forceShutdown();
|
restrictedServer.forceShutdown();
|
||||||
|
@ -276,7 +277,6 @@ describe(`${anyGrpc.clientName} client -> ${anyGrpc.serverName} server`, functio
|
||||||
it('should get an error when requesting a large message', function(done) {
|
it('should get an error when requesting a large message', function(done) {
|
||||||
done = multiDone(done, 2);
|
done = multiDone(done, 2);
|
||||||
restrictedServerClient.unaryCall({response_size: largeMessageSize}, (error, result) => {
|
restrictedServerClient.unaryCall({response_size: largeMessageSize}, (error, result) => {
|
||||||
console.log(result.payload.body.length);
|
|
||||||
assert(error);
|
assert(error);
|
||||||
assert.strictEqual(error.code, grpc.status.RESOURCE_EXHAUSTED);
|
assert.strictEqual(error.code, grpc.status.RESOURCE_EXHAUSTED);
|
||||||
done();
|
done();
|
||||||
|
|
Loading…
Reference in New Issue