Skip to content

http: IncomingMessage not emitting 'end' #10344

@mscdex

Description

@mscdex
  • Version: v4.5.0+
  • Platform: all
  • Subsystem: http

@davidmarkclements brought to my attention an issue that came about in node v4.5.0 where an http.IncomingMessage's 'end' event wasn't being emitted properly when piping to a stream.Writable. The event does get emitted in node v4.4.7 however. Bisecting reveals 6f312b3 as the offending commit.

Test case:

var http = require('http');
var Writable = require('stream').Writable;

http.createServer((req, res) => {
  req.on('end', function() {
    console.log('end');
  });
  var ws = new Writable({
    write: function(data, enc, cb) {
      cb();
      this.emit('finish');
    }
  });
  req.pipe(ws);
}).listen(8080)

It doesn't matter which order the cb() and this.emit('finish') are in or if the emit() is wrapped in a process.nextTick(). If emit() is wrapped in a setImmediate() though, then the 'end' event gets emitted.

/cc @trevnorris @indutny

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues or PRs related to the http subsystem.streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions