fix(http2): move WINDOW_UPDATE handling to remoteSettings event

This commit is contained in:
Koen Rijpstra 2025-06-27 21:38:50 +02:00
parent b69bcad1bb
commit 0e09b9cd59
1 changed files with 13 additions and 12 deletions

View File

@ -723,28 +723,29 @@ export class Http2SubchannelConnector implements SubchannelConnector {
}
});
// Send WINDOW_UPDATE now to avoid 65 KB start-window stall.
// 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;
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);
}
}
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);