Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle closed connection when downloading sentry-cli binary #1389

Merged
merged 1 commit into from Nov 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions scripts/install.js
Expand Up @@ -258,19 +258,29 @@ async function downloadBinary() {
decompressor = new stream.PassThrough();
}
const name = downloadUrl.match(/.*\/(.*?)$/)[1];
const total = parseInt(response.headers.get('content-length'), 10);
const progressBar = createProgressBar(name, total);
let downloadedBytes = 0;
const totalBytes = parseInt(response.headers.get('content-length'), 10);
const progressBar = createProgressBar(name, totalBytes);
const tempPath = getTempFile(cachedPath);
fs.mkdirSync(path.dirname(tempPath), { recursive: true });

await new Promise((resolve, reject) => {
response.body
.on('error', (e) => reject(e))
.on('data', (chunk) => progressBar.tick(chunk.length))
.on('data', (chunk) => {
downloadedBytes += chunk.length;
progressBar.tick(chunk.length);
})
.pipe(decompressor)
.pipe(fs.createWriteStream(tempPath, { mode: '0755' }))
.on('error', (e) => reject(e))
.on('close', () => resolve());
.on('close', () => {
if (downloadedBytes >= totalBytes) {
resolve();
} else {
reject(new Error('connection interrupted'));
}
});
});

if (process.env.SENTRYCLI_SKIP_CHECKSUM_VALIDATION !== '1') {
Expand Down