Skip to content

Commit 027a33a

Browse files
authored
Cache agent (#1122)
* Cache agent * Use Lazy
1 parent 9e89034 commit 027a33a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/platform/networking/node/nodeFetchFetcher.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as undici from 'undici';
77
import { IEnvService } from '../../env/common/envService';
88
import { BaseFetchFetcher } from './baseFetchFetcher';
9+
import { Lazy } from '../../../util/vs/base/common/lazy';
910

1011
export class NodeFetchFetcher extends BaseFetchFetcher {
1112

@@ -32,6 +33,9 @@ export class NodeFetchFetcher extends BaseFetchFetcher {
3233
function getFetch(): typeof globalThis.fetch {
3334
const fetch = (globalThis as any).__vscodePatchedFetch || globalThis.fetch;
3435
return function (input: string | URL | globalThis.Request, init?: RequestInit) {
35-
return fetch(input, { dispatcher: new undici.Agent({ allowH2: true }), ...init });
36+
return fetch(input, { dispatcher: agent.value, ...init });
3637
};
3738
}
39+
40+
// Cache agent to reuse connections.
41+
const agent = new Lazy(() => new undici.Agent({ allowH2: true }));

0 commit comments

Comments
 (0)