Skip to content

Commit 12cdf9f

Browse files
authored
fix unreturned promise in fastify hooks (DataDog#2049)
1 parent c399351 commit 12cdf9f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/datadog-instrumentations/src/fastify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function wrapAddHook (addHook) {
4545

4646
if (!requestResource) return fn.apply(this, arguments)
4747

48-
requestResource.runInAsyncScope(() => {
48+
return requestResource.runInAsyncScope(() => {
4949
const hookResource = new AsyncResource('bound-anonymous-fn')
5050

5151
try {

packages/datadog-plugin-fastify/test/index.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,22 @@ describe('Plugin', () => {
279279
})
280280
})
281281

282+
// This is a regression test for https://github.com/DataDog/dd-trace-js/issues/2047
283+
it('should not time out on async hooks', (done) => {
284+
app.addHook('onRequest', async (request, reply) => {})
285+
286+
app.get('/user', (request, reply) => {
287+
reply.send()
288+
})
289+
290+
getPort().then(port => {
291+
app.listen(port, 'localhost', async () => {
292+
await axios.get(`http://localhost:${port}/user`)
293+
done()
294+
})
295+
})
296+
})
297+
282298
it('should handle hook errors', done => {
283299
let error
284300

0 commit comments

Comments
 (0)