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

fix: set grpc keepalive time|outs by default #1814

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions src/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,16 @@ export class PubSub {
private schemaClient?: SchemaServiceClient;

constructor(options?: ClientConfig) {
options = Object.assign({}, options || {});

// Needed for potentially large responses that may come from using exactly-once delivery.
// This will get passed down to grpc client objects.
const maxMetadataSize = 'grpc.max_metadata_size';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const optionsAny = options as any;
if (optionsAny[maxMetadataSize] === undefined) {
optionsAny[maxMetadataSize] = 4 * 1024 * 1024; // 4 MiB
}
// Needed for potentially large responses that may come from using exactly-once delivery,
// as well as trying to work around silent connection failures.
//
// These will get passed down to grpc client objects. User values will overwrite these.
const grpcDefaults = {
'grpc.max_metadata_size': 4 * 1024 * 1024, // 4 MiB
'grpc.keepalive_time_ms': 300000, // 5 minutes
'grpc.keepalive_timeout_ms': 20000, // 20 seconds
hongalex marked this conversation as resolved.
Show resolved Hide resolved
};
options = Object.assign(grpcDefaults, options || {});

// Determine what scopes are needed.
// It is the union of the scopes on both clients.
Expand Down
13 changes: 12 additions & 1 deletion test/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,16 @@ describe('PubSub', () => {

describe('instantiation', () => {
const maxMetadataSizeKey = 'grpc.max_metadata_size';
const keepaliveTimeKey = 'grpc.keepalive_time_ms';
const keepaliveTimeoutKey = 'grpc.keepalive_timeout_ms';

const DEFAULT_OPTIONS = {
libName: 'gccl',
libVersion: PKG.version,
scopes: [],
[maxMetadataSizeKey]: 4 * 1024 * 1024,
[keepaliveTimeKey]: 300000,
[keepaliveTimeoutKey]: 20000,
};

it('should extend the correct methods', () => {
Expand All @@ -216,18 +221,24 @@ describe('PubSub', () => {
assert(new PubSub() instanceof PubSub);
});

it('should augment the gRPC options for metadata size', () => {
it('should augment the gRPC options', () => {
let pubsub = new PubSub();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let optionsAny: any = pubsub.options;
assert.strictEqual(optionsAny[maxMetadataSizeKey], 4 * 1024 * 1024);
assert.strictEqual(optionsAny[keepaliveTimeKey], 300000);
assert.strictEqual(optionsAny[keepaliveTimeoutKey], 20000);

optionsAny = {
[maxMetadataSizeKey]: 1 * 1024 * 1024,
[keepaliveTimeKey]: 30,
[keepaliveTimeoutKey]: 100,
};
pubsub = new PubSub(optionsAny);
optionsAny = pubsub.options;
assert.strictEqual(optionsAny[maxMetadataSizeKey], 1 * 1024 * 1024);
assert.strictEqual(optionsAny[keepaliveTimeKey], 30);
assert.strictEqual(optionsAny[keepaliveTimeoutKey], 100);
});

it('should combine all required scopes', () => {
Expand Down