Skip to content

Response Event For Aborted Requests Has Status Code Of 200 #4072

@crumkev

Description

@crumkev

Support plan

  • which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community
  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes

Context

  • node version: 12.16.0
  • module version with issue: 18.4.1, 19.1.1
  • last module version without issue: unsure
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): hapi application
  • any other relevant information: similar to Aborted requests show status code 200 in response event #3878

What are you trying to achieve or the steps to reproduce?

I have a hapi server with a route that performs a potentially long-running calculation before responding. Sometimes clients timeout or abort their request before the server has responded. When this occurs, the server logs the response status code as 200 rather than 499. I don't believe this is an issue with the logger, because both good/good-console and hapi-pino have the same behavior.

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

What result did you expect?

Response status code to be 499 (not 200).

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