Merge pull request #2971 from KoenRijpstra/fix/early-connection-window-update

Fix: send connection-level WINDOW_UPDATE at session start
This commit is contained in:
Michael Lumish 2025-08-11 15:54:59 -07:00 committed by GitHub
commit 6573a0ebe4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 1 deletions

View File

@ -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);