Skip to content

"disconnect" event on the "request" object is never emitted #3528

Description

@jfromaniello

This is a simple test where I create a HAPI server with a route that replies with "hello world" after 2 seconds. The same code contains a client that does a request to the route and aborts it after 500ms.

const request = require('request');
const Hapi = require('hapi');

const server = new Hapi.Server();

server.connection({
  host: 'localhost',
  port: 3001,
});

server.route({
  method: 'GET',
  path:'/slow',
  handler: function (request, reply) {
    request.once('disconnect', () => {
      console.log('disconnected');
    });
    setTimeout(() => reply('hello world'), 2000);
  }
});

server.start();

setTimeout(() => {
  console.log('starting request');
  const req = request.get('http://localhost:3001/slow');
  setTimeout(() => {
    console.log('aborting request');
    req.abort();
  }, 500);
}, 1000);

According to the documentation the request object should emit a disconnect event. After debugging for a while I notice that HAPI subscribes to the event too late when the route calls the reply function.

I have tried with version hapi@16.4.3 and node v6.

Thank you very much in advance.

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions