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.
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.
According to the documentation the request object should emit a
disconnectevent. After debugging for a while I notice that HAPI subscribes to the event too late when the route calls thereplyfunction.I have tried with version
hapi@16.4.3and node v6.Thank you very much in advance.