FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

http2: throw better error when accessing unbound socket proxy by jasnell · Pull Request #22486 · nodejs/node · GitHub

/ node Public

http2: throw better error when accessing unbound socket proxy - #22486

Closed
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:http2-proxy-socket-unbound
Closed

http2: throw better error when accessing unbound socket proxy#22486
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:http2-proxy-socket-unbound

Conversation

jasnell commented Aug 23, 2018

Copy link
Copy Markdown
Member

Fixes the bug in the sense that a better error message is provided. Generally speaking, once the connection has been closed, users should not continue to the use the socket proxy object. So, throw whenever they try to.

Fixes: #22268

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Copy link
Copy Markdown
Collaborator

nodejs-github-bot added dont-land-on-v6.x errors Issues and PRs related to JavaScript errors originated in Node.js core. http2 Issues or PRs related to the http2 subsystem. labels Aug 23, 2018

Copy link
Copy Markdown
Member

There's another ways to expose the original socket:

session.socket.ref()
session.socket.unref()
session.socket.setEncoding()
session.socket.setKeepAlive()
session.socket.setNoDelay()

Should these be fixed?

BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I am not sure if this is the ideal solution but the code looks good to me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What is expected to happen sync?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What do you mean?

jasnell commented Aug 23, 2018

Copy link
Copy Markdown
Member Author

Should these be fixed?

Yeah, I'll take another look.

jasnell force-pushed the http2-proxy-socket-unbound branch from 3bb3522 to dc92650 Compare August 24, 2018 18:27

jasnell commented Aug 24, 2018

Copy link
Copy Markdown
Member Author

Added additional tests for the ref(), unref(), setEncoding(), setKeepAlive(), and setNoDelay() functions.

jasnell commented Aug 24, 2018

Copy link
Copy Markdown
Member Author

jasnell added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Aug 24, 2018

Trott commented Aug 25, 2018

Copy link
Copy Markdown
Member

Trott commented Aug 25, 2018
edited
Loading

Copy link
Copy Markdown
Member

Theoretically semver-major (I think?) if it doesn't end up in the same release as the "HTTP/2 is stable!" thing, so let's get this thing landed.

I personally don't know that I would have chosen an HTTP2 error for this (and others) instead of one of the existing SOCKET errors, but maybe more specific is good and I make bad decisions. 🙃

Trott commented Aug 25, 2018

Copy link
Copy Markdown
Member

@nodejs/http2

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

jasnell added a commit that referenced this pull request Aug 27, 2018
Fixes: #22268

PR-URL: #22486
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>

jasnell commented Aug 27, 2018

Copy link
Copy Markdown
Member Author

Landed in dd03706

jasnell closed this Aug 27, 2018
addaleax pushed a commit that referenced this pull request Aug 27, 2018
Fixes: #22268

PR-URL: #22486
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>

Copy link
Copy Markdown
Member

@jasnell I think you missed something :P

You can't do session.socket.destroy() because it'll throw ERR_HTTP2_NO_SOCKET_MANIPULATION, but you can do session.socket.ref().destroy(). As I said, these functions expose the original socket:

session.socket.ref()
session.socket.unref()
session.socket.setEncoding()
session.socket.setKeepAlive()
session.socket.setNoDelay()

So ProxySocket should look like:

  get(session, prop) {
    switch (prop) {
      case 'setTimeout':
        return session.setTimeout.bind(session);
      case 'destroy':
      case 'emit':
      case 'end':
      case 'pause':
      case 'read':
      case 'resume':
      case 'write':
      case 'setEncoding':
      case 'setKeepAlive':
      case 'setNoDelay':
        throw new ERR_HTTP2_NO_SOCKET_MANIPULATION();
      case 'ref':
      case 'unref':
        return socket[prop].bind(session.socket);
      default:
        const socket = session[kSocket];
        if (socket === undefined)
          throw new ERR_HTTP2_SOCKET_UNBOUND();
        const value = socket[prop];
        return typeof value === 'function' ? value.bind(socket) : value;
    }
  }
...
  set(session, prop, value) {
    switch (prop) {
      case 'setTimeout':
        session.setTimeout = value;
        return true;
      case 'destroy':
      case 'emit':
      case 'end':
      case 'pause':
      case 'read':
      case 'resume':
      case 'write':
      case 'setEncoding':
      case 'setKeepAlive':
      case 'setNoDelay':
      case 'ref':
      case 'unref':
        throw new ERR_HTTP2_NO_SOCKET_MANIPULATION();
      default:
        const socket = session[kSocket];
        if (socket === undefined)
          throw new ERR_HTTP2_SOCKET_UNBOUND();
        socket[prop] = value;
        return true;
    }

Copy link
Copy Markdown
Member

@szmarczak good spot! would you like to open a PR to fix that?

Copy link
Copy Markdown
Member

Yeah, sure.

Copy link
Copy Markdown
Member

@mcollina Here it is: #22650

targos pushed a commit that referenced this pull request Sep 3, 2018
Fixes: #22268

PR-URL: #22486
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
mcollina pushed a commit that referenced this pull request Sep 5, 2018
Refs: #22486

PR-URL: #22650
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Sep 5, 2018
Refs: #22486

PR-URL: #22650
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Sep 6, 2018
Fixes: #22268

PR-URL: #22486
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos pushed a commit that referenced this pull request Sep 6, 2018
Refs: #22486

PR-URL: #22650
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
kjin pushed a commit to kjin/node that referenced this pull request Oct 3, 2018
Fixes: nodejs#22268

PR-URL: nodejs#22486
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
kjin pushed a commit to kjin/node that referenced this pull request Oct 3, 2018
Refs: nodejs#22486

PR-URL: nodejs#22650
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
kjin pushed a commit to kjin/node that referenced this pull request Oct 16, 2018
Fixes: nodejs#22268

PR-URL: nodejs#22486
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
kjin pushed a commit to kjin/node that referenced this pull request Oct 16, 2018
Refs: nodejs#22486

PR-URL: nodejs#22650
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BethGriggs pushed a commit that referenced this pull request Oct 17, 2018
Fixes: #22268

Backport-PR-URL: #22850
PR-URL: #22486
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
BethGriggs pushed a commit that referenced this pull request Oct 17, 2018
Refs: #22486

Backport-PR-URL: #22850
PR-URL: #22650
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BethGriggs mentioned this pull request Oct 30, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. errors Issues and PRs related to JavaScript errors originated in Node.js core. http2 Issues or PRs related to the http2 subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessing socket after HTTP2 session gets destroyed throws an error

7 participants


Back | FazBrowse Home | New Git URL