-
Notifications
You must be signed in to change notification settings - Fork 421
fix: Replace request.abort with response.close in HTTP instrumentation #1510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
02421ef
f78c4d5
3900424
0997b3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2023 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
const fork = require('child_process').fork | ||
const tap = require('tap') | ||
const helper = require('../../lib/agent_helper') | ||
const metrics = require('../../lib/metrics_helper') | ||
|
||
function generateApp() { | ||
const express = require('express') | ||
const bodyParser = require('body-parser') | ||
|
||
const app = express() | ||
app.use(bodyParser.json()) | ||
|
||
app.post('/test', async function controller(req, res) { | ||
try { | ||
await new Promise((resolve) => | ||
setTimeout(() => { | ||
resolve() | ||
}, req.body.timeout) | ||
) | ||
|
||
res.status(200).send('OK') | ||
} catch (err) { | ||
res.status(500).send('Err') | ||
} | ||
}) | ||
|
||
return app | ||
} | ||
|
||
tap.test('Client Premature Disconnection', (t) => { | ||
t.setTimeout(3000) | ||
const agent = helper.instrumentMockedAgent() | ||
const server = generateApp().listen(0) | ||
const { port } = server.address() | ||
|
||
t.teardown(() => { | ||
server.close() | ||
helper.unloadAgent(agent) | ||
}) | ||
|
||
agent.on('transactionFinished', (transaction) => { | ||
t.doesNotThrow(function () { | ||
metrics.assertSegments( | ||
transaction.trace.root, | ||
[ | ||
'WebTransaction/Expressjs/POST//test', | ||
[ | ||
'Nodejs/Middleware/Expressjs/query', | ||
'Nodejs/Middleware/Expressjs/expressInit', | ||
'Nodejs/Middleware/Expressjs/jsonParser', | ||
'Expressjs/Route Path: /test', | ||
['Nodejs/Middleware/Expressjs/controller', ['timers.setTimeout']] | ||
] | ||
], | ||
{ exact: true } | ||
) | ||
}, 'should have expected segments') | ||
|
||
t.equal(agent.getTransaction(), null, 'should have ended the transaction') | ||
t.end() | ||
}) | ||
|
||
const forkedRequest = fork(`${__dirname}/helpers/request.js`) | ||
forkedRequest.send(port) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2023 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
// Polyfill till we drop support for Node 14 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we cut a ticket to remove this when we drop 14? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually replaced the abort controller with request.destroy, so no need to use the abort controller anymore |
||
const { AbortController } = require('node-abort-controller') | ||
const axios = require('axios') | ||
|
||
process.on('message', (port) => { | ||
const controller = new AbortController() | ||
axios | ||
jmartin4563 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.post(`http://localhost:${port}/test`, { timeout: 1500 }, { signal: controller.signal }) | ||
.catch(() => { | ||
// eslint-disable-next-line no-process-exit | ||
process.exit() | ||
}) | ||
|
||
setTimeout(() => { | ||
controller.abort() | ||
}, 100) | ||
}) |
Uh oh!
There was an error while loading. Please reload this page.