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

http: response should always emit close on finish #20043

Closed
wants to merge 2 commits into from

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Apr 15, 2018

Fixes: #17352

Original PR was posted at #17397

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

@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Apr 15, 2018
@trivikr
Copy link
Member Author

trivikr commented Apr 15, 2018

@trivikr
Copy link
Member Author

trivikr commented Apr 15, 2018

Rerun for node-test-commit-freebsd https://ci.nodejs.org/job/node-test-commit-freebsd/17043/

if (res) {
if (res.readable) {
// Socket closed before we emitted 'end' below.
res.emit('aborted');
Copy link
Member

Choose a reason for hiding this comment

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

The !req.res.complete condition is gone, is this wanted?

Copy link
Member

Choose a reason for hiding this comment

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

No, definitely not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there any edit required here?

Copy link
Member

Choose a reason for hiding this comment

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

It should have if (!req.res.complete) req.res.emit('aborted');. I would check the rest too. There have been changes to that part of code since that original PR was started.

Copy link
Member Author

Choose a reason for hiding this comment

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

Corrected in 8ffc3c7

if (!req.res.complete) req.res.emit('aborted');
var res = req.res;
res.on('end', function() {
var res = req.res;
Copy link
Member

Choose a reason for hiding this comment

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

const here.

Copy link
Member Author

Choose a reason for hiding this comment

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

changed in 8ffc3c7

@apapirovski
Copy link
Member

This will need CITGM run and also, if we don't have something like on-finished in our CitGM then those tests should run separately to make sure.

@BridgeAR
Copy link
Member

@ronag
Copy link
Member

ronag commented Apr 16, 2018

I think we need to handle the !res.readable case better, i.e. if response has been emitted on the request object we should always emit aborted on the response object.

  if (res) {
    // *******
    // NOTE: if `req.emit('response')` has been emitted we must always emit `aborted`, regardless of whether the response is readable or not.
    // Socket closed before we emitted 'end' below.
    if (!res.complete) {
      res.emit('aborted');
    }
    // *******
    if (res.readable) {
      res.on('end', function() {
        res.emit('close');
      });
      res.push(null);
    } else {
      res.emit('close');
    }
  }

@ronag
Copy link
Member

ronag commented Apr 16, 2018

Should we make the order of req vs res emit close consistent? Right now it is not, i.e we could change it to so that req.emit('close') is always emitted first.

This would avoid intermittent bugs in code that depend on the order.

  if (res) {
    if (res.readable) {
      // Socket closed before we emitted 'end' below.
      if (!res.complete) {
        res.emit('aborted');
      }
      req.emit('close'); // !! Emit close before or after aborted?
      res.on('end', function() {
        res.emit('close');
      });
      res.push(null);
    } else {
      req.emit('close'); // !!
      res.emit('close');
    }
  } else if (!req.socket._hadError) {
    // This socket error fired before we started to
    // receive a response. The error needs to
    // fire on the request.
    req.socket._hadError = true;
    req.emit('error', createHangUpError());
    req.emit('close');  // !!
  } else {
    req.emit('close');  // !!
  }

@ronag ronag mentioned this pull request Apr 16, 2018
3 tasks
@ronag
Copy link
Member

ronag commented Apr 16, 2018

#20075, feel free to cherry-pick

@BridgeAR
Copy link
Member

Ping @trivikr

@trivikr
Copy link
Member Author

trivikr commented Apr 23, 2018

Closing this PR as the other one #20075 includes this change (along with additional changes by @ronag)

@trivikr trivikr closed this Apr 23, 2018
@trivikr trivikr deleted the http-client-reponse-emit-close branch August 31, 2023 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http.ClientRequest response object only emits close after abort?
6 participants