Skip to content
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

http2: fix ping callback #20311

Closed
wants to merge 2 commits into from

Conversation

BridgeAR
Copy link
Member

In case there was no ack, the callback would have returned
more than the error as return value. This makes sure that is not
the case anymore.

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

@nodejs-github-bot nodejs-github-bot added dont-land-on-v4.x http2 Issues or PRs related to the http2 subsystem. labels Apr 26, 2018
@BridgeAR
Copy link
Member Author

BridgeAR commented Apr 26, 2018

In case there was no ack, the callback would have returned
more than the error as return value. This makes sure that is not
the case anymore.
If `common.expectsError` is used as a callback, it will now also
verify that there is only one argument (the expected error).
@BridgeAR BridgeAR force-pushed the fix-http2-ping-callback branch from 56e627b to 6202d98 Compare April 26, 2018 11:21
@BridgeAR
Copy link
Member Author

@nodejs/http @nodejs/http2 PTAL

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

Passing the payload is intentional here as that is what is used to correlate. I'm -1 to removing it.

@BridgeAR
Copy link
Member Author

@jasnell can you please elaborate? IMO this is against the default Node.js callback standard. In case of an error we normally only return the error and nothing else.

@jasnell
Copy link
Member

jasnell commented Apr 26, 2018

function pingCallback(err, duration, payload) {
  if (err) {
    console.log(`Ping with payload "${payload.toString()}" failed`);
  } else {
    console.log(`Ping with payload "${payload.toString()}" succeeded with duration ${duration}`);
  }
}

session.ping(Buffer.from('12345678'), pingCallback);
session.ping(Buffer.from('87654321'), pingCallback);

@BridgeAR
Copy link
Member Author

To me this is very surprising to rely on any arguments if an error was returned.

Any other opinions @nodejs/http2 @nodejs/tsc?

@addaleax
Copy link
Member

As long as it’s documented this way, what are the issues with providing more information than just the error?

@BridgeAR
Copy link
Member Author

Somewhat related: #20335

The documentation states:

The callback will be invoked with three arguments: an error argument that will be null if the PING was 
successfully acknowledged, a duration argument that reports the number of milliseconds elapsed since 
the ping was sent and the acknowledgment was received, and a Buffer containing the 8-byte PING 
payload.

The payload will be undefined in case of an error and there is no ack, so there should also not be a elapsed time, but the time is actually returned in case of an error. I do not even know what the returned time should now stand for and that seems like a bug to me.

Aside from that I expect all Node.js callbacks to always only return the error in an error case. Otherwise it seems like Schrödinger's cat to me. You get some results but also an error. What should you now work with?

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 27, 2018
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

BridgeAR added a commit to BridgeAR/node that referenced this pull request Apr 29, 2018
In case there was no ack, the callback would have returned
more than the error as return value. This makes sure that is not
the case anymore.

PR-URL: nodejs#20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Apr 29, 2018
If `common.expectsError` is used as a callback, it will now also
verify that there is only one argument (the expected error).

PR-URL: nodejs#20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
@BridgeAR
Copy link
Member Author

Landed in bb546ac and 29cddb4

@BridgeAR BridgeAR closed this Apr 29, 2018
MylesBorins pushed a commit that referenced this pull request May 4, 2018
In case there was no ack, the callback would have returned
more than the error as return value. This makes sure that is not
the case anymore.

PR-URL: #20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
MylesBorins pushed a commit that referenced this pull request May 4, 2018
If `common.expectsError` is used as a callback, it will now also
verify that there is only one argument (the expected error).

PR-URL: #20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
@MylesBorins MylesBorins mentioned this pull request May 8, 2018
kjin pushed a commit to kjin/node that referenced this pull request Aug 23, 2018
In case there was no ack, the callback would have returned
more than the error as return value. This makes sure that is not
the case anymore.

PR-URL: nodejs#20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
kjin pushed a commit to kjin/node that referenced this pull request Aug 23, 2018
If `common.expectsError` is used as a callback, it will now also
verify that there is only one argument (the expected error).

PR-URL: nodejs#20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
kjin pushed a commit to kjin/node that referenced this pull request Sep 11, 2018
In case there was no ack, the callback would have returned
more than the error as return value. This makes sure that is not
the case anymore.

PR-URL: nodejs#20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
kjin pushed a commit to kjin/node that referenced this pull request Sep 11, 2018
If `common.expectsError` is used as a callback, it will now also
verify that there is only one argument (the expected error).

PR-URL: nodejs#20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
kjin pushed a commit to kjin/node that referenced this pull request Sep 19, 2018
In case there was no ack, the callback would have returned
more than the error as return value. This makes sure that is not
the case anymore.

PR-URL: nodejs#20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
kjin pushed a commit to kjin/node that referenced this pull request Sep 19, 2018
If `common.expectsError` is used as a callback, it will now also
verify that there is only one argument (the expected error).

PR-URL: nodejs#20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
kjin pushed a commit to kjin/node that referenced this pull request Oct 16, 2018
In case there was no ack, the callback would have returned
more than the error as return value. This makes sure that is not
the case anymore.

PR-URL: nodejs#20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
kjin pushed a commit to kjin/node that referenced this pull request Oct 16, 2018
If `common.expectsError` is used as a callback, it will now also
verify that there is only one argument (the expected error).

PR-URL: nodejs#20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
BethGriggs pushed a commit that referenced this pull request Oct 17, 2018
In case there was no ack, the callback would have returned
more than the error as return value. This makes sure that is not
the case anymore.

Backport-PR-URL: #22850
PR-URL: #20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
BethGriggs pushed a commit that referenced this pull request Oct 17, 2018
If `common.expectsError` is used as a callback, it will now also
verify that there is only one argument (the expected error).

Backport-PR-URL: #22850
PR-URL: #20311
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
@BethGriggs BethGriggs mentioned this pull request Oct 30, 2018
@BridgeAR BridgeAR deleted the fix-http2-ping-callback branch January 20, 2020 11:32
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 pending requests for changes, and a CI started. http2 Issues or PRs related to the http2 subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants