Skip to content

Commit

Permalink
fix: keep alive tcp connection when downloading binary (#1791)
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Dec 29, 2023
1 parent abd10ed commit 2ddb04f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import binLinks from "bin-links";
import { createHash } from "crypto";
import fs from "fs";
import fetch from "node-fetch";
import { Agent } from "https";
import { HttpsProxyAgent } from "https-proxy-agent";
import path from "path";
import tar from "tar";
Expand Down Expand Up @@ -128,7 +129,12 @@ async function main() {
process.env.npm_config_https_proxy ||
process.env.npm_config_http_proxy ||
process.env.npm_config_proxy;
const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl) : undefined;

// Keeps the TCP connection alive when sending multiple requests
// Ref: https://github.com/node-fetch/node-fetch/issues/1735
const agent = proxyUrl
? new HttpsProxyAgent(proxyUrl, { keepAlive: true })
: new Agent({ keepAlive: true });
const resp = await fetch(url, { agent });

const hash = createHash("sha256");
Expand Down

0 comments on commit 2ddb04f

Please sign in to comment.