diff --git a/packages/grpc-js/src/transport.ts b/packages/grpc-js/src/transport.ts index ba0675d08..3767b4cf0 100644 --- a/packages/grpc-js/src/transport.ts +++ b/packages/grpc-js/src/transport.ts @@ -719,14 +719,33 @@ export class Http2SubchannelConnector implements SubchannelConnector { settings: { initialWindowSize: options['grpc-node.flow_control_window'] ?? - http2.getDefaultSettings().initialWindowSize, + http2.getDefaultSettings().initialWindowSize ?? 65535, } }); + + // Prepare window size configuration for remoteSettings handler + const defaultWin = http2.getDefaultSettings().initialWindowSize ?? 65535; // 65 535 B + const connWin = options[ + 'grpc-node.flow_control_window' + ] as number | undefined; + this.session = session; let errorMessage = 'Failed to connect'; let reportedError = false; session.unref(); session.once('remoteSettings', () => { + // Send WINDOW_UPDATE now to avoid 65 KB start-window stall. + if (connWin && connWin > defaultWin) { + try { + // Node ≥ 14.18 + (session as any).setLocalWindowSize(connWin); + } catch { + // Older Node: bump by the delta + const delta = connWin - (session.state.localWindowSize ?? defaultWin); + if (delta > 0) (session as any).incrementWindowSize(delta); + } + } + session.removeAllListeners(); secureConnectResult.socket.removeListener('close', closeHandler); secureConnectResult.socket.removeListener('error', errorHandler);