镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Cannot reuse a TLS socket for a HTTP2 session #33343

Description

@szmarczak

What steps will reproduce the bug?

const http2 = require('http2');
const tls = require('tls');

const options = {
  ALPNProtocols: ['h2'],
  host: 'nghttp2.org',
  servername: 'nghttp2.org',
  port: 443,
  settings: {}
};

tls._connect = tls.connect;

/*
tls.connect = (...args) => {
    console.log(...args, args[1].toString());
    return tls._connect(...args);
};
*/

const socket = tls._connect(options, () => {
    console.log('Connected!');
    const session = http2.connect('https://nghttp2.org', {
        createConnection: () => socket
    });

    session.once('remoteSettings', () => {
        console.log('Received remote settings!');
    });
});

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

Always.

What is the expected behavior?

Connected!
Received remote settings!

What do you see instead?

Connected!

Additional information

Reference: #16256

Activity

  1. rickyes commented on May 11, 2020

    @rickyes
    Contributor

    The latest code does not reproduce this issue.

  2. szmarczak commented on May 11, 2020

    @szmarczak
    MemberAuthor

    What latest code? Do you mean Node.js master branch?

  3. rickyes commented on May 11, 2020

    @rickyes
    Contributor

    Yes, it may have been fixed in some commit, I didn't reproduce this issue in macOS v10.14.

  4. szmarczak commented on May 11, 2020

    @szmarczak
    MemberAuthor

    Indeed, it's fixed on the master branch. Feel free to close the issue, but I'd prefer to keep this open until there's a release that fixes it.

  5. szmarczak commented on Jul 14, 2020

    @szmarczak
    MemberAuthor

    Closing since a fix has been released a while ago.

  6. pimterry commented on Aug 18, 2020

    @pimterry
    Member

    I ran into this too. I've done some quick tests with the repro above, and:

    • I can reproduce this in the latest Node 12 (12.18.3)
    • I can't reproduce this in Node 14.3+. It fails in 14.1 & 14.2, but seems to be fixed from that point onwards. I've specifically tested 14.3, 14.6 and 14.8 (the latest release).

    Doing some digging through the changelog, looks like this is the fix: #33209.

    That hasn't yet been backported to v12 though. It'd be great if that could be included in the next v12 release to get this fixed, since it causes some big problems for lots of interesting HTTP/2 use cases (like detecting HTTP/2 support during TLS setup, as in https://github.com/szmarczak/http2-wrapper/). I'm not sure where to get started with making that happen, but maybe @addaleax can help?

  7. fenying commented on Aug 19, 2020

    @fenying

    Same here, I tested v8.17.0, v10.22.0, v12.18.3, v14.8.0, and only v12.18.3 could reproduce this problem.

    see my reproduce: https://github.com/fenying/nodejs-bug-code-h2-binding

    @szmarczak

  8. grantila commented on Aug 20, 2020

    @grantila

    This is a really serious bug, could it please be opened up? cc @addaleax

  9. grantila commented on Aug 20, 2020

    @grantila

    Especially serious since 12 is LTS. My fetch-h2 package, which is relatively well used is totally broken because of this.

  10. addaleax commented on Aug 20, 2020

    @addaleax
    Member

    @grantila Correct me if I’m wrong, but based on the conversation above, backporting #33209 to v12.x would fix this, right? I’ll open a backport PR as suggested over there, there isn’t really anything to do here in the issue anymore. If there’s still problems with backporting, feel free to help with debugging those

  11. addaleax commented on Aug 20, 2020

    @addaleax
    Member
  12. addaleax commented on Aug 20, 2020

    @addaleax
    Member

    @grantila Also, I might be wrong, but if the fix works, then socket.on('secureConnect', () => socket.secureConnecting = false); should be a functional workaround.

  13. grantila commented on Aug 20, 2020

    @grantila

    I'll be damned, it does work @addaleax, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions