-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Cannot reuse an estabilished TLS socket for a HTTP/2 session #35475
Comments
What does |
|
I think that the socket must have no data buffered. Putting |
Dunno... Wrapping `socket` like this makes things workconst http2 = require('http2');
const tls = require('tls');
const stream = require('stream');
const options = {
ALPNProtocols: ['h2'],
host: 'nghttp2.org',
servername: 'nghttp2.org',
port: 443
};
const socket = tls.connect(options, async () => {
console.log('Connected!');
await new Promise(resolve => setTimeout(resolve, 1000));
const proxy = new stream.Duplex({
read(...args) {
const x = socket.read();
if (x !== null) {
this.push(x);
}
},
final(...args) {
socket.end(...args);
},
write(...args) {
socket.write(...args);
},
destroy(...args) {
socket.destroy(...args);
}
});
const session = http2.connect('https://nghttp2.org', {
createConnection: () => proxy
});
session.once('remoteSettings', () => {
console.log('Received remote settings!');
});
}); |
@szmarczak your analysis is correct, the problem is the data awaiting in the socket on the JS side When the TLS code establishes the connections, it asks for HTTP2 via APLN. The remote server sends immediately its SETTINGS frame which is received by the TLS code and kept in its buffer. Now, the question is how is this supposed to work 😃 // Socket already has some buffered data - emulate receiving it
if (socket && socket.readableLength) {
let buf;
while ((buf = socket.read()) !== null)
tlsSocket._handle.receive(buf);
} and this: void TLSWrap::Receive(const FunctionCallbackInfo<Value>& args) {
TLSWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
ArrayBufferViewContents<char> buffer(args[0]);
const char* data = buffer.data();
size_t len = buffer.length();
Debug(wrap, "Receiving %zu bytes injected from JS", len); The HTTP2 code doesn't seem to support injection from JS - or I was unable to find it? |
Reinject the data already received from the TLS socket when the HTTP2 client is attached with a delay Fixes: nodejs#35475
Reinject the data already received from the TLS socket when the HTTP2 client is attached with a delay Fixes: nodejs#35475
|
Reinject the data already received from the TLS socket when the HTTP2 client is attached with a delay Fixes: #35475 PR-URL: #35678 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Alba Mendez <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ricky Zhou <[email protected]>
Reinject the data already received from the TLS socket when the HTTP2 client is attached with a delay Fixes: #35475 PR-URL: #35678 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Alba Mendez <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ricky Zhou <[email protected]>
Reinject the data already received from the TLS socket when the HTTP2 client is attached with a delay Fixes: #35475 PR-URL: #35678 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Alba Mendez <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ricky Zhou <[email protected]>
Reinject the data already received from the TLS socket when the HTTP2 client is attached with a delay Fixes: #35475 PR-URL: #35678 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Alba Mendez <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ricky Zhou <[email protected]>
Linux solus 5.6.19-158.current #1 SMP PREEMPT Sun Jul 26 14:17:01 UTC 2020 x86_64 GNU/Linux
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
What do you see instead?
Additional information
This is similar to #33343
The text was updated successfully, but these errors were encountered: