nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.78k stars 29.14k forks source link

Cannot call `session.setLocalWindowSize(number)` before session connects #38427

Open szmarczak opened 3 years ago

szmarczak commented 3 years ago

What steps will reproduce the bug?

const http2 = require('http2');

const session = http2.connect('https://example.com');

// Throws
session.setLocalWindowSize(1024 * 1024 * 16);

session.on('remoteSettings', () => {
    // Doesn't throw
    session.setLocalWindowSize(1024 * 1024 * 16);
    console.log('Success!');
});

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior?

No error.

What do you see instead?

node:internal/http2/core:1290
    const ret = this[kHandle].setLocalWindowSize(windowSize);
                              ^

TypeError: Cannot read property 'setLocalWindowSize' of undefined
    at ClientHttp2Session.setLocalWindowSize (node:internal/http2/core:1290:31)
    at Object.<anonymous> (/home/szm/Desktop/http2-wrapper/demo.js:6:9)
    at Module._compile (node:internal/modules/cjs/loader:1091:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:10)
    at Module.load (node:internal/modules/cjs/loader:971:32)
    at Function.Module._load (node:internal/modules/cjs/loader:812:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

Related with #38426

ZYSzys commented 3 years ago

The session's handle hasn't been setup before session connects.

Why not setLocalWindowSize in the connect callback listener ?

const session = http2.connect('https://example.com', () => {
  session.setLocalWindowSize(1024 * 1024 * 16);
});
szmarczak commented 3 years ago

Still an issue as of v16.4.2

saeedjhn commented 2 years ago

Please Check:

`const clientHttp2Session = http2.connect(authority, {}, (session, socket) => { session.setLocalWindowSize(2 5); console.log(session.state); // effectiveLocalWindowSize: 2 5 });

const stream = clientHttp2Session.request(); `