Skip to content

Commit 6573a0e

Browse files
authored
Merge pull request #2971 from KoenRijpstra/fix/early-connection-window-update
Fix: send connection-level WINDOW_UPDATE at session start
2 parents c7c6ae5 + a8d22dc commit 6573a0e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

packages/grpc-js/src/transport.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,14 +719,33 @@ export class Http2SubchannelConnector implements SubchannelConnector {
719719
settings: {
720720
initialWindowSize:
721721
options['grpc-node.flow_control_window'] ??
722-
http2.getDefaultSettings().initialWindowSize,
722+
http2.getDefaultSettings().initialWindowSize ?? 65535,
723723
}
724724
});
725+
726+
// Prepare window size configuration for remoteSettings handler
727+
const defaultWin = http2.getDefaultSettings().initialWindowSize ?? 65535; // 65 535 B
728+
const connWin = options[
729+
'grpc-node.flow_control_window'
730+
] as number | undefined;
731+
725732
this.session = session;
726733
let errorMessage = 'Failed to connect';
727734
let reportedError = false;
728735
session.unref();
729736
session.once('remoteSettings', () => {
737+
// Send WINDOW_UPDATE now to avoid 65 KB start-window stall.
738+
if (connWin && connWin > defaultWin) {
739+
try {
740+
// Node ≥ 14.18
741+
(session as any).setLocalWindowSize(connWin);
742+
} catch {
743+
// Older Node: bump by the delta
744+
const delta = connWin - (session.state.localWindowSize ?? defaultWin);
745+
if (delta > 0) (session as any).incrementWindowSize(delta);
746+
}
747+
}
748+
730749
session.removeAllListeners();
731750
secureConnectResult.socket.removeListener('close', closeHandler);
732751
secureConnectResult.socket.removeListener('error', errorHandler);

0 commit comments

Comments
 (0)