Skip to content

Commit 0e09b9c

Browse files
committed
fix(http2): move WINDOW_UPDATE handling to remoteSettings event
1 parent b69bcad commit 0e09b9c

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

packages/grpc-js/src/transport.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -723,28 +723,29 @@ export class Http2SubchannelConnector implements SubchannelConnector {
723723
}
724724
});
725725

726-
// Send WINDOW_UPDATE now to avoid 65 KB start-window stall.
726+
// Prepare window size configuration for remoteSettings handler
727727
const defaultWin = http2.getDefaultSettings().initialWindowSize ?? 65535; // 65 535 B
728728
const connWin = options[
729729
'grpc-node.flow_control_window'
730730
] 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-
}
742731

743732
this.session = session;
744733
let errorMessage = 'Failed to connect';
745734
let reportedError = false;
746735
session.unref();
747736
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+
748749
session.removeAllListeners();
749750
secureConnectResult.socket.removeListener('close', closeHandler);
750751
secureConnectResult.socket.removeListener('error', errorHandler);

0 commit comments

Comments
 (0)