Skip to content

Fix: send connection-level WINDOW_UPDATE at session start #2971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/grpc-js/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,30 @@ export class Http2SubchannelConnector implements SubchannelConnector {
http2.getDefaultSettings().initialWindowSize,
}
});

// 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);
Expand Down