-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Support plan
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: 12.13.1, 14.15.1
- module version with issue: 19.2.0, 20.0.1, 20.1.2 (maybe others)
- last module version without issue: unsure
- environment (e.g. node, browser, native): node
- used with (e.g. hapi application, another framework, standalone, ...): hapi-application, another framework
- any other relevant information: similar to Response Event For Aborted Requests Has Status Code Of 200 #4072
What are you trying to achieve or the steps to reproduce?
const Hapi = require('@hapi/hapi');
const server = Hapi.server({
host: 'localhost',
port: 8080,
});
server.route({
method: 'GET',
path: '/abort-test',
handler: async function() {
return new Promise(function (resolve) {
setTimeout(function () {
resolve('OK');
}, 4000);
});
},
})
server.events.on('request', (request, event) => {
console.log(`Event: ${JSON.stringify(event)}`);
});
server.events.on('response', (request) => {
console.log(`Response Status Code: ${request.response.statusCode}`);
});
server.start();
console.log(`Server running at: ${server.info.uri}`);
curl --max-time 1 http://localhost:8080/abort-test
What was the result you got?
Server running at: http://localhost:8080
Event: {"request":"<SHORTENED>","timestamp":1584125752386,"tags":["request","error","abort"],"channel":"internal"}
Response Status Code: 200
Native node.js response.end isn't called.
What result did you expect?
response.end
called, response status code to be 499.
Additional info
We're using opentelemetry.js to collect metrics from our application, it has a module that automatically collects HTTP metrics by wrapping native node's http
and https
modules.
It works fine with usual HTTP requests to our hapi-app, but when a request is aborted on a client side - it doesn't collect metrics.
I assume that it's because Hapi.js doesn't call native response.end
for aborted requests, which is wrapped with opentelemetry module. It works fine with native node.js HTTP service (because it calls response.end
even for aborted requests). So it would be nice to get some help and understand if there a bug in Hapi request abort mechanism or should we deal some specific way with aborted requests to be able to collect metrics in this case.