Skip to content

Commit d872278

Browse files
committed
fix(http2): bump connection window immediately after connect()
If the user sets `grpc-node.connection_flow_control_window` to a value > 65 535 B, we now send a WINDOW_UPDATE (or setLocalWindowSize) right after `http2.connect()` returns. This removes the 65 KB start-window stall that caused large initial backlogs on high-throughput streams, especially when an H2 proxy (e.g. HAProxy) sat between client and server. Behaviour now matches Go/Rust gRPC; no API changes.
1 parent 179dbfa commit d872278

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/grpc-js/src/transport.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,24 @@ export class Http2SubchannelConnector implements SubchannelConnector {
722722
http2.getDefaultSettings().initialWindowSize,
723723
}
724724
});
725+
726+
// Send WINDOW_UPDATE now to avoid 65 KB start-window stall.
727+
const defaultWin = http2.getDefaultSettings().initialWindowSize; // 65 535 B
728+
const connWin = options[
729+
'grpc-node.connection_flow_control_window'
730+
] as number | undefined;
731+
732+
if (connWin && connWin > defaultWin) {
733+
try {
734+
// Node ≥ 14.18
735+
(session as any).setLocalWindowSize(connWin);
736+
} catch {
737+
// Older Node: bump by the delta
738+
const delta = connWin - (session.state.localWindowSize ?? defaultWin);
739+
if (delta > 0) (session as any).incrementWindowSize(delta);
740+
}
741+
}
742+
725743
this.session = session;
726744
let errorMessage = 'Failed to connect';
727745
let reportedError = false;

0 commit comments

Comments
 (0)