Skip to content

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

@msmol

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues or PRs related to the http subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions