Skip to content

Node 10: http response.close is always triggered #21063

Description

@msmol
  • Version: Node 10.3.0
  • Platform: Linux 4.16.11
  • Subsystem: http

index.js:

const http = require('http');

http.createServer((req, res) => {
  res.writeHead(200);
  
  res.on('finish', () => {
    console.log('finish');
  });

  res.on('close', () => {
    console.log('close');
  });
  
  res.end();

}).listen(3000);
$ nvm use 10; node index.js
Now using node v10.3.0 (npm v6.1.0) # run curl localhost:3000 now
finish
close
^C
$ nvm use 8; node index.js
Now using node v8.9.4 (npm v5.6.0) # run curl localhost:3000 now
finish
^C
$

According to the docs res.close should only be called if res.end is not. Unfortunately there doesn't seem to be an event emitted for res.end so I could not check to see whether or not it was triggered.

However, as is visible in the example above:

  • Node 8
    • finish event triggered
    • close event not triggered,
  • Node 10
    • finish event triggered
    • close event triggered

Activity

  1. mscdex commented on May 31, 2018

    @mscdex
    Contributor

    Related: #21047
    Ref: #20611

  2. msmol commented on May 31, 2018

    @msmol
    Author

    If I understand correctly, #21047 implies that res.close always being called is now considered the correct behavior?

  3. added
    httpIssues and PRs related to the http subsystem.
    on Jul 26, 2018
  4. addaleax commented on Jul 26, 2018

    @addaleax
    Member

    @nodejs/http Anything to do here?

  5. targos commented on Jul 26, 2018

    @targos
    Member

    We are in the process of reverting the change in #21809

  6. added a commit that references this issue on Aug 29, 2018
  7. apapirovski commented on Oct 18, 2018

    @apapirovski
    Contributor

    Sounds like there's nothing left to address here. The change was reverted.

  8. Srinivas-Vemula commented on Jan 17, 2020

    @Srinivas-Vemula

    we are seeing this issue on Node V12.13.x.

  9. mscdex commented on Jan 17, 2020

    @mscdex
    Contributor

    @Srinivas-Vemula That's expected as the change was kept in master, it was only reverted for v10.x.

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

    httpIssues and PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions