Skip to content

Commit e8d8a2f

Browse files
authored
fix: deal with Symbol(undici.globalDispatcher.1) in Node.js 18+ (#1058)
1 parent 4966a5f commit e8d8a2f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/modules/leaks.js

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ internals.getNodeGlobals = async () => {
118118
};
119119

120120
if (!WorkerThreads.isMainThread) {
121+
122+
// Accessing FormData does a lazy require of undici inside Node.js 18+, which in turn exposes
123+
// the `Symbol(undici.globalDispatcher.1)`. In earlier Node.js versions this is a no-op.
124+
typeof FormData;
125+
121126
// When this module is used as a worker, it posts back global property names and symbols
122127
WorkerThreads.parentPort.postMessage({
123128
allowed: Object.getOwnPropertyNames(globalThis),

test/leaks.js

+9
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ describe('Leaks', () => {
153153
expect(leaks.length).to.equal(0);
154154
});
155155

156+
it('ignores undici global', async () => {
157+
158+
// trigger a lazy require of Undici, where supported, to expose a `Symbol(undici.globalDispatcher.1)`
159+
typeof FormData;
160+
161+
const leaks = await Lab.leaks.detect();
162+
expect(leaks.length).to.equal(0);
163+
});
164+
156165
it('identifies custom globals', async () => {
157166

158167
testedKeys.push('abc');

0 commit comments

Comments
 (0)