Skip to content

Commit f3594be

Browse files
Yukio0315mcollina
authored andcommitted
feat: preserve undici agent by default
Documentation states destroyAgent defaults to false but the option was undefined when omitted, causing custom ag ents to be destroyed. Explicitly default the option to f alse and cover it with a regression test. Signed-off-by: Yukio Ueda <triangle.pillow@gmail.com>
1 parent 8c0d65d commit f3594be

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

lib/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function buildRequest (opts) {
5353
const isBalanced = Array.isArray(opts.base) && opts.base.length > 1
5454
const undiciOpts = opts.undici || {}
5555
const globalAgent = opts.globalAgent
56-
const destroyAgent = opts.destroyAgent
56+
const destroyAgent = opts.destroyAgent || false
5757
let http2Client
5858
let undiciAgent
5959
let undiciInstance

test/undici-no-destroy.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,25 @@ test('destroyAgent false', async (t) => {
2727
await instance.ready()
2828
await instance.close()
2929
})
30+
31+
test('destroyAgent default false', async (t) => {
32+
const mockAgent = new undici.Agent()
33+
mockAgent.destroy = () => {
34+
t.fail()
35+
}
36+
const instance = Fastify()
37+
38+
t.after(() => instance.close())
39+
40+
instance.get('/', (_request, reply) => {
41+
reply.from()
42+
})
43+
44+
instance.register(From, {
45+
base: 'http://localhost:4242',
46+
undici: mockAgent
47+
})
48+
49+
await instance.ready()
50+
await instance.close()
51+
})

0 commit comments

Comments
 (0)