Skip to content

Commit bee9e95

Browse files
committed
destroy agents
1 parent 337541f commit bee9e95

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

packages/@aws-cdk/toolkit-lib/lib/api/aws-auth/awscli-compatible.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -270,28 +270,19 @@ export interface CredentialChainOptions {
270270
}
271271

272272
export function sdkRequestHandler(agent?: Agent): RequestHandlerSettings {
273-
const destroyAgents = (config: RequestHandlerSettings) => {
274-
try {
275-
config.httpAgent?.destroy();
276-
} catch (_) {
277-
}
278-
try {
279-
config.httpsAgent?.destroy();
280-
} catch (_) {
281-
}
282-
};
273+
process.on('beforeExit', () => {
274+
// eslint-disable-next-line no-console
275+
console.log('Cleaning up SDK resources before exit...');
276+
agent?.destroy();
277+
});
278+
process.on('SIGINT', () => {
279+
agent?.destroy(); process.exit();
280+
});
283281

284-
const result = {
282+
return {
285283
connectionTimeout: DEFAULT_CONNECTION_TIMEOUT,
286284
requestTimeout: DEFAULT_TIMEOUT,
287285
httpsAgent: agent,
288286
httpAgent: agent,
289287
};
290-
291-
process.on('beforeExit', () => destroyAgents(result));
292-
process.on('SIGINT', () => {
293-
destroyAgents(result); process.exit();
294-
});
295-
296-
return result;
297288
}

0 commit comments

Comments
 (0)