From ad68f6391aa2f240973e30df66d6008516508867 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 4 Dec 2024 20:02:58 -0700 Subject: [PATCH] Destroy agent instances when disposed from cache (#350) Co-authored-by: Anna Henningsen --- .changeset/unlucky-vans-shout.md | 5 +++++ packages/proxy-agent/src/index.ts | 5 ++++- pnpm-lock.yaml | 24 ++++++++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 .changeset/unlucky-vans-shout.md diff --git a/.changeset/unlucky-vans-shout.md b/.changeset/unlucky-vans-shout.md new file mode 100644 index 00000000..0f2a5c81 --- /dev/null +++ b/.changeset/unlucky-vans-shout.md @@ -0,0 +1,5 @@ +--- +'proxy-agent': patch +--- + +Dispose of Agent instances in cache correctly diff --git a/packages/proxy-agent/src/index.ts b/packages/proxy-agent/src/index.ts index 496e185a..b3a8b36b 100644 --- a/packages/proxy-agent/src/index.ts +++ b/packages/proxy-agent/src/index.ts @@ -83,7 +83,10 @@ export class ProxyAgent extends Agent { /** * Cache for `Agent` instances. */ - cache = new LRUCache({ max: 20 }); + cache = new LRUCache({ + max: 20, + dispose: (agent) => agent.destroy(), + }); connectOpts?: ProxyAgentOptions; httpAgent: http.Agent; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f5a17797..90f9a954 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -273,7 +273,7 @@ importers: version: 4.3.4 get-uri: specifier: ^6.0.1 - version: link:../get-uri + version: 6.0.4 http-proxy-agent: specifier: ^7.0.0 version: link:../http-proxy-agent @@ -408,7 +408,7 @@ importers: version: link:../https-proxy-agent lru-cache: specifier: ^7.14.1 - version: 7.14.1 + version: 7.18.3 pac-proxy-agent: specifier: ^7.0.2 version: link:../pac-proxy-agent @@ -2687,6 +2687,11 @@ packages: engines: {node: '>=0.4.0'} dev: true + /data-uri-to-buffer@6.0.2: + resolution: {integrity: sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw==} + engines: {node: '>= 14'} + dev: false + /dateformat@1.0.7-1.2.3: resolution: {integrity: sha512-rzAoghPcnojOgYhvqb9ZYR5Ws9hDM2SGB6xLSUX9pEAKYnbxyexHZypDLgx3+SF3SR+at6waVRCxKDm6q2Z6+g==} dev: true @@ -3305,6 +3310,17 @@ packages: get-intrinsic: 1.2.1 dev: true + /get-uri@6.0.4: + resolution: {integrity: sha512-E1b1lFFLvLgak2whF2xDBcOy6NLVGZBqqjJjsIhvopKfWWEi64pLVTWWehV8KlLerZkfNTA95sTe2OdJKm1OzQ==} + engines: {node: '>= 14'} + dependencies: + basic-ftp: 5.0.2 + data-uri-to-buffer: 6.0.2 + debug: 4.3.4 + transitivePeerDependencies: + - supports-color + dev: false + /glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} @@ -4414,8 +4430,8 @@ packages: yallist: 4.0.0 dev: true - /lru-cache@7.14.1: - resolution: {integrity: sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA==} + /lru-cache@7.18.3: + resolution: {integrity: sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==} engines: {node: '>=12'} dev: false