Skip to content

Commit 1b9eb31

Browse files
deps: update undici to 7.24.5
1 parent 7547e79 commit 1b9eb31

File tree

8 files changed

+162
-111
lines changed

8 files changed

+162
-111
lines changed

deps/undici/src/docs/docs/best-practices/writing-tests.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,46 @@ const agent = new Agent({
1818

1919
setGlobalDispatcher(agent)
2020
```
21+
22+
## Guarding against unexpected disconnects
23+
24+
Undici's `Client` automatically reconnects after a socket error. This means
25+
a test can silently disconnect, reconnect, and still pass. Unfortunately,
26+
this could mask bugs like unexpected parser errors or protocol violations.
27+
To catch these silent reconnections, add a disconnect guard after creating
28+
a `Client`:
29+
30+
```js
31+
const { Client } = require('undici')
32+
const { test, after } = require('node:test')
33+
const { tspl } = require('@matteo.collina/tspl')
34+
35+
test('example with disconnect guard', async (t) => {
36+
t = tspl(t, { plan: 1 })
37+
38+
const client = new Client('http://localhost:3000')
39+
after(() => client.close())
40+
41+
client.on('disconnect', () => {
42+
if (!client.closed && !client.destroyed) {
43+
t.fail('unexpected disconnect')
44+
}
45+
})
46+
47+
// ... test logic ...
48+
})
49+
```
50+
51+
`client.close()` and `client.destroy()` both emit `'disconnect'` events, but
52+
those are expected. The guard only fails when a disconnect happens during the
53+
active test (i.e., `!client.closed && !client.destroyed` is true).
54+
55+
Skip the guard for tests where a disconnect is expected behavior, such as:
56+
57+
- Signal aborts (`signal.emit('abort')`, `ac.abort()`)
58+
- Server-side destruction (`res.destroy()`, `req.socket.destroy()`)
59+
- Client-side body destruction mid-stream (`data.body.destroy()`)
60+
- Timeout errors (`HeadersTimeoutError`, `BodyTimeoutError`)
61+
- Successful upgrades (the socket is detached from the `Client`)
62+
- Retry/reconnect tests where the disconnect triggers the retry
63+
- HTTP parser errors from malformed responses (`HTTPParserError`)

deps/undici/src/lib/handler/cache-handler.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,18 @@ function determineDeleteAt (now, cacheControlDirectives, staleAt) {
493493
staleIfError = staleAt + (cacheControlDirectives['stale-if-error'] * 1000)
494494
}
495495

496-
if (staleWhileRevalidate === -Infinity && staleIfError === -Infinity) {
496+
if (cacheControlDirectives.immutable && staleWhileRevalidate === -Infinity && staleIfError === -Infinity) {
497497
immutable = now + 31536000000
498498
}
499499

500+
// When no stale directives or immutable flag, add a revalidation buffer
501+
// equal to the freshness lifetime so the entry survives past staleAt long
502+
// enough to be revalidated instead of silently disappearing.
503+
if (staleWhileRevalidate === -Infinity && staleIfError === -Infinity && immutable === -Infinity) {
504+
const freshnessLifetime = staleAt - now
505+
return staleAt + freshnessLifetime
506+
}
507+
500508
return Math.max(staleAt, staleWhileRevalidate, staleIfError, immutable)
501509
}
502510

deps/undici/src/lib/llhttp/wasm_build_env.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
> undici@7.24.4 build:wasm
2+
> undici@7.24.5 build:wasm
33
> node build/wasm.js --docker
44

55
> docker run --rm --platform=linux/x86_64 --user 1001:1001 --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/lib/llhttp,target=/home/node/build/lib/llhttp --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/build,target=/home/node/build/build --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/deps,target=/home/node/build/deps -t ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970 node build/wasm.js

deps/undici/src/lib/web/fetch/formdata-parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const { makeEntry } = require('./formdata')
66
const { webidl } = require('../webidl')
77
const assert = require('node:assert')
88
const { isomorphicDecode } = require('../infra')
9-
const { utf8DecodeBytes } = require('../../encoding')
109

1110
const dd = Buffer.from('--')
1211
const decoder = new TextDecoder()
12+
const decoderIgnoreBOM = new TextDecoder('utf-8', { ignoreBOM: true })
1313

1414
/**
1515
* @param {string} chars
@@ -188,7 +188,7 @@ function multipartFormDataParser (input, mimeType) {
188188
// 5.11. Otherwise:
189189

190190
// 5.11.1. Let value be the UTF-8 decoding without BOM of body.
191-
value = utf8DecodeBytes(Buffer.from(body))
191+
value = decoderIgnoreBOM.decode(Buffer.from(body))
192192
}
193193

194194
// 5.12. Assert: name is a scalar value string and value is either a scalar value string or a File object.

0 commit comments

Comments
 (0)