Skip to content

client.on("response", ...) event does not include err=RequestAbortedError if aborted during productCheck()Β #1517

@trentm

Description

@trentm

πŸ› Bug Report

In v7.14.0 a request that is aborted quickly (while the productCheck() request is still going) properly results in the request callback (or promise resolution) including the RequestAbortedError instance. However, the emitted Client "response" event does not include that RequestAbortedError instance.

This is a challenge for https://github.com/elastic/apm-agent-nodejs which is attempting to use the "request" and "response" Client events for APM tracing. This means APM will not report an error for a quick abort.

To Reproduce

  1. Save this as "esfoo.js"
const { Client } = require('@elastic/elasticsearch')
var client = new Client({
  node: 'http://localhost:9200',
  auth: { username: 'admin', password: 'changeme' }
})

client.on('response', function (err, event) {
  console.log('"response" event: err=', err && err.name)
})

var req = client.search(
  { body: { size: 1 } },
  function (err, _result) {
    console.log('callback: err:', err && err.name)
  }
)
setImmediate(function () {
  req.abort()
})

with earlier versions:

% npm ls @elastic/elasticsearch
elastic-apm-node@3.19.0 /Users/trentm/el/apm-agent-nodejs8
└── @elastic/elasticsearch@7.13.0

% node esfoo.js
"response" event: err= RequestAbortedError
callback: err: RequestAbortedError

with v7.14.0:

% npm ls @elastic/elasticsearch
elastic-apm-node@3.19.0 /Users/trentm/el/apm-agent-nodejs8
└── @elastic/elasticsearch@7.14.0

% node esfoo.js
"response" event: err= null
callback: err: RequestAbortedError

Expected behavior

I realize the "response" event being sent here is for the Transport.prototype.request for the productCheck() so it might not be complete straightforward. Could the req.abort() be passed through to the productCheck request if it is ongoing?

Your Environment

  • node version: v12.22.1
  • os: Mac

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions