Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

http response pause lets event loop exit when there's an actively ref'd connection #6305

@tjfontaine

Description

@tjfontaine

While there's nothing really for the child to continue doing here, so long as the connection is alive the loop should also be alive.

var common = require('../common')
var assert = require('assert');

var spawn = require('child_process').execFile;
var http = require('http');

var TOTAL_BYTES = 100 * 1024 * 1024;

if (process.argv[2] === 'child') {
  var seen = 0;

  http.get({
      hostname: '127.0.0.1',
      port: common.PORT,
      path: '/',
  }, function (res) {
      console.log('%d\ns', res.statusCode, JSON.stringify(res.headers, null, 2));

      res.on('data', function (chunk) {
        seen += chunk.length;
        console.error('chunk received: %d', chunk.length);
        res.pause();
      });

      res.once('end', function () {
        console.error('ended');
      });
  });

  process.on('exit', function() {
    // this isn't technically right, but it's more the fact that the loop is
    // exiting before it should
    console.error(seen, TOTAL_BYTES);
    assert.strictEqual(seen, TOTAL_BYTES);
  });
} else {
  var buff = new Buffer(TOTAL_BYTES);
  var server = http.createServer(function(req, res) {
    console.log('sending', buff.length);
    res.end(buff);
  }).listen(common.PORT, function() {
    var child = spawn(process.execPath,
      [process.argv[1], 'child'],
      {} //{ env: { NODE_DEBUG: 'http net' } }
    );
    child.on('close', function(code) {
      console.log('closing server');
      server.close();
      assert.strictEqual(code, 0);
    });
    child.stderr.pipe(process.stderr);
    child.stdout.pipe(process.stdout);
  });
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions