From d08318d8c10c3cd19c993db7619018c72eaadf4e Mon Sep 17 00:00:00 2001 From: Ricki Hastings Date: Fri, 6 Dec 2024 11:48:31 +0000 Subject: [PATCH 1/3] fix: allow configurable http2 initial window size. fixes #2429 --- packages/grpc-js/README.md | 1 + packages/grpc-js/src/channel-options.ts | 2 ++ packages/grpc-js/src/transport.ts | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/packages/grpc-js/README.md b/packages/grpc-js/README.md index dfe805021..42d579854 100644 --- a/packages/grpc-js/README.md +++ b/packages/grpc-js/README.md @@ -70,6 +70,7 @@ Many channel arguments supported in `grpc` are not supported in `@grpc/grpc-js`. - `grpc-node.max_session_memory` - `grpc-node.tls_enable_trace` - `grpc-node.retry_max_attempts_limit` + - `grpc-node.http2_initial_window_size` - `channelOverride` - `channelFactoryOverride` diff --git a/packages/grpc-js/src/channel-options.ts b/packages/grpc-js/src/channel-options.ts index e605d3f76..04c26b03a 100644 --- a/packages/grpc-js/src/channel-options.ts +++ b/packages/grpc-js/src/channel-options.ts @@ -64,6 +64,7 @@ export interface ChannelOptions { 'grpc-node.tls_enable_trace'?: number; 'grpc.lb.ring_hash.ring_size_cap'?: number; 'grpc-node.retry_max_attempts_limit'?: number; + 'grpc-node.http2_initial_window_size'?: number; // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any; } @@ -101,6 +102,7 @@ export const recognizedOptions = { 'grpc-node.tls_enable_trace': true, 'grpc.lb.ring_hash.ring_size_cap': true, 'grpc-node.retry_max_attempts_limit': true, + 'grpc-node.http2_initial_window_size': true, }; export function channelOptionsEqual( diff --git a/packages/grpc-js/src/transport.ts b/packages/grpc-js/src/transport.ts index 97c2ffbcd..bb9257df5 100644 --- a/packages/grpc-js/src/transport.ts +++ b/packages/grpc-js/src/transport.ts @@ -672,6 +672,11 @@ export class Http2SubchannelConnector implements SubchannelConnector { const session = http2.connect(`http://${targetPath}`, { createConnection: (authority, option) => { return underlyingConnection; + }, + settings: { + initialWindowSize: + options['grpc-node.http2_initial_window_size'] || + http2.getDefaultSettings().initialWindowSize, } }); this.session = session; From a0914c6cdada66e66c4e20839d93b160129543c2 Mon Sep 17 00:00:00 2001 From: Ricki Hastings Date: Thu, 2 Jan 2025 08:56:53 +0000 Subject: [PATCH 2/3] fix: rename variable and use nullish coalesce --- packages/grpc-js/README.md | 2 +- packages/grpc-js/src/channel-options.ts | 2 +- packages/grpc-js/src/transport.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/grpc-js/README.md b/packages/grpc-js/README.md index 42d579854..7b1ff43c1 100644 --- a/packages/grpc-js/README.md +++ b/packages/grpc-js/README.md @@ -70,7 +70,7 @@ Many channel arguments supported in `grpc` are not supported in `@grpc/grpc-js`. - `grpc-node.max_session_memory` - `grpc-node.tls_enable_trace` - `grpc-node.retry_max_attempts_limit` - - `grpc-node.http2_initial_window_size` + - `grpc-node.flow_control_window` - `channelOverride` - `channelFactoryOverride` diff --git a/packages/grpc-js/src/channel-options.ts b/packages/grpc-js/src/channel-options.ts index 04c26b03a..32c9df6b5 100644 --- a/packages/grpc-js/src/channel-options.ts +++ b/packages/grpc-js/src/channel-options.ts @@ -64,7 +64,7 @@ export interface ChannelOptions { 'grpc-node.tls_enable_trace'?: number; 'grpc.lb.ring_hash.ring_size_cap'?: number; 'grpc-node.retry_max_attempts_limit'?: number; - 'grpc-node.http2_initial_window_size'?: number; + 'grpc-node.flow_control_window'?: number; // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any; } diff --git a/packages/grpc-js/src/transport.ts b/packages/grpc-js/src/transport.ts index bb9257df5..558624021 100644 --- a/packages/grpc-js/src/transport.ts +++ b/packages/grpc-js/src/transport.ts @@ -675,7 +675,7 @@ export class Http2SubchannelConnector implements SubchannelConnector { }, settings: { initialWindowSize: - options['grpc-node.http2_initial_window_size'] || + options['grpc-node.flow_control_window'] ?? http2.getDefaultSettings().initialWindowSize, } }); From c591c2a26862e176ff29b6c3520d381e52d1d2d8 Mon Sep 17 00:00:00 2001 From: Ricki Hastings Date: Thu, 2 Jan 2025 08:57:44 +0000 Subject: [PATCH 3/3] fix: update channel-options.ts --- packages/grpc-js/src/channel-options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/grpc-js/src/channel-options.ts b/packages/grpc-js/src/channel-options.ts index 32c9df6b5..e1555c815 100644 --- a/packages/grpc-js/src/channel-options.ts +++ b/packages/grpc-js/src/channel-options.ts @@ -102,7 +102,7 @@ export const recognizedOptions = { 'grpc-node.tls_enable_trace': true, 'grpc.lb.ring_hash.ring_size_cap': true, 'grpc-node.retry_max_attempts_limit': true, - 'grpc-node.http2_initial_window_size': true, + 'grpc-node.flow_control_window': true, }; export function channelOptionsEqual(