Skip to content

Commit 706c96a

Browse files
committed
avoid flaky large blob downloads by working around nodejs/node#3055 (avoid 'agent:false')
1 parent 57974ea commit 706c96a

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

CHANGES.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# node-docker-registry-client Changelog
22

3-
## 1.4.2 (not yet released)
3+
## 2.0.0 (not yet released)
44

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

79

810
## 1.4.1
@@ -39,7 +41,7 @@
3941
//...
4042
});
4143

42-
On side-effect of this change is the underlying HTTP connections no longer
44+
One side-effect of this change is the underlying HTTP connections no longer
4345
set `agent: false` to avoid Node's default HTTP agent. This means that if you
4446
are **not** using a proxy, you will now get keep-alive, which means a
4547
persistent connection that could hold your node script/app from exiting. All

lib/registry-client-v2.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ function RegistryClientV2(opts) {
586586
this._url = common.urlFromIndex(this.repo.index);
587587
}
588588

589+
this._clientsToClose = [];
590+
589591
Object.defineProperty(this, '_api', {
590592
get: function () {
591593
if (self.__api === undefined) {
@@ -596,13 +598,28 @@ function RegistryClientV2(opts) {
596598
rejectUnauthorized: !this.insecure,
597599
userAgent: self.userAgent
598600
});
601+
self._clientsToClose.push(self.__api);
599602
}
600603
return this.__api;
601604
}
602605
});
603606
}
604607

605608

609+
RegistryClientV2.prototype.version = 2;
610+
611+
612+
RegistryClientV2.prototype.close = function close() {
613+
for (var i = 0; i < this._clientsToClose.length; i++) {
614+
var client = this._clientsToClose[i];
615+
this.log.trace({host: client.url && client.url.host},
616+
'close http client');
617+
client.close();
618+
}
619+
this._clientsToClose = [];
620+
};
621+
622+
606623
/**
607624
* Get a registry session token from docker.io.
608625
*
@@ -714,18 +731,6 @@ RegistryClientV2.prototype._login = function _login(cb) {
714731
});
715732
};
716733

717-
RegistryClientV2.prototype.version = 2;
718-
719-
720-
RegistryClientV2.prototype.close = function close() {
721-
if (this.__api) {
722-
this.__api.close();
723-
}
724-
if (this.__rawApi) {
725-
this.__rawApi.close();
726-
}
727-
};
728-
729734

730735
//RegistryClientV2.prototype._saveCookies = function _saveCookies(url, res) {
731736
// var header = res.headers['set-cookie'];
@@ -947,10 +952,12 @@ RegistryClientV2.prototype._headOrGetBlob = function _headOrGetBlob(opts, cb) {
947952
var client = restify.createHttpClient({
948953
url: reqOpts.url,
949954
log: self.log,
950-
agent: false,
955+
// XXX common opts: agent, proxy
951956
rejectUnauthorized: !self.insecure,
952957
userAgent: self.userAgent
953958
});
959+
self._clientsToClose.push(client);
960+
954961
client[opts.method](reqOpts, function _onConn(connErr, req) {
955962
if (connErr) {
956963
next(connErr);

0 commit comments

Comments
 (0)