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

Node 10: close event is still emitted on normal HTTP response #25294

Closed
borisovg opened this issue Dec 31, 2018 · 3 comments
Closed

Node 10: close event is still emitted on normal HTTP response #25294

borisovg opened this issue Dec 31, 2018 · 3 comments

Comments

@borisovg
Copy link

According to #21063 and #21809 in Node v10 HTTP response should not emit 'close' if 'end' was emitted, but it still does:

'use strict';

const http = require('http');

const server = http.createServer(function (req, res) {
    res.end('OK');
});

console.log(process.versions);

server.listen(8080, function () {
    const req = http.get('http://localhost:8080/', function (res) {
        res.on('data', function (chunk) {
            console.log(`DATA: ${chunk}`);
        });

        res.on('close', function () {
            console.log('CLOSE');
        });

        res.on('end', function () {
            console.log('END');
            server.close();
        });
    });

    req.end();
});

output:

{ http_parser: '2.8.0',
  node: '10.15.0',
  v8: '6.8.275.32-node.45',
  uv: '1.23.2',
  zlib: '1.2.11',
  ares: '1.15.0',
  modules: '64',
  nghttp2: '1.34.0',
  napi: '3',
  openssl: '1.1.0j',
  icu: '62.1',
  unicode: '11.0',
  cldr: '33.1',
  tz: '2018e' }
DATA: OK
END
CLOSE
@mscdex
Copy link
Contributor

mscdex commented Dec 31, 2018

res in this case is an IncomingMessage (a Readable stream), which is documented as having a 'close' event. Also FWIW in #21063 the res there is a ServerResponse (a Writable stream), which is a different issue.

@borisovg
Copy link
Author

borisovg commented Dec 31, 2018

@mscdex you are correct

This is the output in Node v8:

{ http_parser: '2.8.1',
  node: '8.11.4',
  v8: '6.2.414.54',
  uv: '1.20.2',
  zlib: '1.2.11',
  ares: '1.14.0',
  modules: '57',
  nghttp2: '1.32.0',
  napi: '3',
  openssl: '1.0.2o',
  icu: '60.1',
  unicode: '10.0',
  cldr: '32.0',
  tz: '2017c' }
DATA: OK
END

Change in behaviour is the same.

@borisovg
Copy link
Author

OK, read the docs some more and changed my code to avoid this issue entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants