Skip to content

Commit

Permalink
Fix issue with close event always being emitted
Browse files Browse the repository at this point in the history
This addresses a changed behaviour in Node 10, resulting
from the fact that the `close` event is always being emitted
now. This would have lead to the `place_binary()` callback being
called twice when the HTTP request failed (with e.g. a 404).

Refs: nodejs/node#21063
Fixes: mapbox#391
  • Loading branch information
addaleax committed Jul 26, 2018
1 parent b5081af commit 5eb112c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function place_binary(from,to,opts,callback) {
if (!req) return callback(new Error("empty req"));
var badDownload = false;
var extractCount = 0;
var hasResponse = false;
var tar = require('tar');

function afterTarball(err) {
Expand Down Expand Up @@ -122,7 +123,7 @@ function place_binary(from,to,opts,callback) {
});

req.on('close', function () {
if (extractCount === 0) {
if (!hasResponse) {
return callback(new Error('Connection closed while downloading tarball file'));
}
});
Expand All @@ -132,6 +133,7 @@ function place_binary(from,to,opts,callback) {
if (http_get.type === 'needle' && res.headers.hasOwnProperty('location') && res.headers.location !== '') {
return;
}
hasResponse = true;
if (res.statusCode !== 200) {
badDownload = true;
var err = new Error(res.statusCode + ' status code downloading tarball ' + from);
Expand Down

0 comments on commit 5eb112c

Please sign in to comment.