Skip to content

Commit

Permalink
avoid flaky large blob downloads by working around nodejs/node#3055 (…
Browse files Browse the repository at this point in the history
…avoid 'agent:false')
  • Loading branch information
trentm committed Sep 24, 2015
1 parent 57974ea commit 706c96a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
8 changes: 5 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# node-docker-registry-client Changelog

## 1.4.2 (not yet released)
## 2.0.0 (not yet released)

(nothing yet)
- Fix reliability issues with v2 download of large layer files.
My understanding is that this was due to <https://github.com/nodejs/node/issues/3055>.
This module is now avoiding `agent: false`, at least for the blob downloads.


## 1.4.1
Expand Down Expand Up @@ -39,7 +41,7 @@
//...
});

On side-effect of this change is the underlying HTTP connections no longer
One side-effect of this change is the underlying HTTP connections no longer
set `agent: false` to avoid Node's default HTTP agent. This means that if you
are **not** using a proxy, you will now get keep-alive, which means a
persistent connection that could hold your node script/app from exiting. All
Expand Down
33 changes: 20 additions & 13 deletions lib/registry-client-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ function RegistryClientV2(opts) {
this._url = common.urlFromIndex(this.repo.index);
}

this._clientsToClose = [];

Object.defineProperty(this, '_api', {
get: function () {
if (self.__api === undefined) {
Expand All @@ -596,13 +598,28 @@ function RegistryClientV2(opts) {
rejectUnauthorized: !this.insecure,
userAgent: self.userAgent
});
self._clientsToClose.push(self.__api);
}
return this.__api;
}
});
}


RegistryClientV2.prototype.version = 2;


RegistryClientV2.prototype.close = function close() {
for (var i = 0; i < this._clientsToClose.length; i++) {
var client = this._clientsToClose[i];
this.log.trace({host: client.url && client.url.host},
'close http client');
client.close();
}
this._clientsToClose = [];
};


/**
* Get a registry session token from docker.io.
*
Expand Down Expand Up @@ -714,18 +731,6 @@ RegistryClientV2.prototype._login = function _login(cb) {
});
};

RegistryClientV2.prototype.version = 2;


RegistryClientV2.prototype.close = function close() {
if (this.__api) {
this.__api.close();
}
if (this.__rawApi) {
this.__rawApi.close();
}
};


//RegistryClientV2.prototype._saveCookies = function _saveCookies(url, res) {
// var header = res.headers['set-cookie'];
Expand Down Expand Up @@ -947,10 +952,12 @@ RegistryClientV2.prototype._headOrGetBlob = function _headOrGetBlob(opts, cb) {
var client = restify.createHttpClient({
url: reqOpts.url,
log: self.log,
agent: false,
// XXX common opts: agent, proxy
rejectUnauthorized: !self.insecure,
userAgent: self.userAgent
});
self._clientsToClose.push(client);

client[opts.method](reqOpts, function _onConn(connErr, req) {
if (connErr) {
next(connErr);
Expand Down

0 comments on commit 706c96a

Please sign in to comment.