diff --git a/docs/api_methods_1_0.asciidoc b/docs/api_methods_1_0.asciidoc index 66b0fe717..1c619aa03 100644 --- a/docs/api_methods_1_0.asciidoc +++ b/docs/api_methods_1_0.asciidoc @@ -41,6 +41,7 @@ NOTE: At this time, you must opt into the 1.0 API by setting the `apiVersion` co * <> * <> * <> +* <> * <> * <> * <> @@ -2136,6 +2137,39 @@ The default method is `GET` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-thread-pool.html[the elasticsearch docs] for more about this method. + +// no examples + + +==== Params + +[horizontal] +`local`:: +`Boolean` -- Return local information, do not retrieve the state from master node (default: false) +`masterTimeout`:: +`Date, Number` -- Explicit operation timeout for connection to master node +`h`:: +`String, String[], Boolean` -- Comma-separated list of column names to display +`help`:: +`Boolean` -- Return help information +`v`:: +`Boolean` -- Verbose mode. Display column headers +`fullId`:: +`Boolean` -- Enables displaying the complete node ids + +link:#[back to top] + [[api-cluster-getsettings-1-0]] === `cluster.getSettings` diff --git a/docs/api_methods_1_x.asciidoc b/docs/api_methods_1_x.asciidoc index 9aa524ddc..a7c15c720 100644 --- a/docs/api_methods_1_x.asciidoc +++ b/docs/api_methods_1_x.asciidoc @@ -41,6 +41,7 @@ NOTE: At this time, you must opt into the 1.x API by setting the `apiVersion` co * <> * <> * <> +* <> * <> * <> * <> @@ -2136,6 +2137,39 @@ The default method is `GET` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-thread-pool.html[the elasticsearch docs] for more about this method. + +// no examples + + +==== Params + +[horizontal] +`local`:: +`Boolean` -- Return local information, do not retrieve the state from master node (default: false) +`masterTimeout`:: +`Date, Number` -- Explicit operation timeout for connection to master node +`h`:: +`String, String[], Boolean` -- Comma-separated list of column names to display +`help`:: +`Boolean` -- Return help information +`v`:: +`Boolean` -- Verbose mode. Display column headers +`fullId`:: +`Boolean` -- Enables displaying the complete node ids + +link:#[back to top] + [[api-cluster-getsettings-1-x]] === `cluster.getSettings` diff --git a/docs/api_methods_master.asciidoc b/docs/api_methods_master.asciidoc index c296ba823..dc3ea5e1b 100644 --- a/docs/api_methods_master.asciidoc +++ b/docs/api_methods_master.asciidoc @@ -41,6 +41,7 @@ NOTE: At this time, you must opt into the master API by setting the `apiVersion` * <> * <> * <> +* <> * <> * <> * <> @@ -2136,6 +2137,39 @@ The default method is `GET` and the usual <> apply. See http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-thread-pool.html[the elasticsearch docs] for more about this method. + +// no examples + + +==== Params + +[horizontal] +`local`:: +`Boolean` -- Return local information, do not retrieve the state from master node (default: false) +`masterTimeout`:: +`Date, Number` -- Explicit operation timeout for connection to master node +`h`:: +`String, String[], Boolean` -- Comma-separated list of column names to display +`help`:: +`Boolean` -- Return help information +`v`:: +`Boolean` -- Verbose mode. Display column headers +`fullId`:: +`Boolean` -- Enables displaying the complete node ids + +link:#[back to top] + [[api-cluster-getsettings-master]] === `cluster.getSettings` diff --git a/src/lib/apis/1_0.js b/src/lib/apis/1_0.js index 47e63256d..0479b8aec 100644 --- a/src/lib/apis/1_0.js +++ b/src/lib/apis/1_0.js @@ -565,6 +565,48 @@ api.cat.prototype.shards = ca({ ] }); +/** + * Perform a [cat.threadPool](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-thread-pool.html) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.local - Return local information, do not retrieve the state from master node (default: false) + * @param {Date, Number} params.masterTimeout - Explicit operation timeout for connection to master node + * @param {String, String[], Boolean} params.h - Comma-separated list of column names to display + * @param {Boolean} params.help - Return help information + * @param {Boolean} params.v - Verbose mode. Display column headers + * @param {Boolean} params.fullId - Enables displaying the complete node ids + */ +api.cat.prototype.threadPool = ca({ + params: { + local: { + type: 'boolean' + }, + masterTimeout: { + type: 'time', + name: 'master_timeout' + }, + h: { + type: 'list' + }, + help: { + type: 'boolean', + 'default': false + }, + v: { + type: 'boolean', + 'default': false + }, + fullId: { + type: 'boolean', + 'default': false, + name: 'full_id' + } + }, + url: { + fmt: '/_cat/thread_pool' + } +}); + /** * Perform a [clearScroll](http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/search-request-scroll.html) request * diff --git a/src/lib/apis/1_x.js b/src/lib/apis/1_x.js index 47e63256d..0479b8aec 100644 --- a/src/lib/apis/1_x.js +++ b/src/lib/apis/1_x.js @@ -565,6 +565,48 @@ api.cat.prototype.shards = ca({ ] }); +/** + * Perform a [cat.threadPool](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-thread-pool.html) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.local - Return local information, do not retrieve the state from master node (default: false) + * @param {Date, Number} params.masterTimeout - Explicit operation timeout for connection to master node + * @param {String, String[], Boolean} params.h - Comma-separated list of column names to display + * @param {Boolean} params.help - Return help information + * @param {Boolean} params.v - Verbose mode. Display column headers + * @param {Boolean} params.fullId - Enables displaying the complete node ids + */ +api.cat.prototype.threadPool = ca({ + params: { + local: { + type: 'boolean' + }, + masterTimeout: { + type: 'time', + name: 'master_timeout' + }, + h: { + type: 'list' + }, + help: { + type: 'boolean', + 'default': false + }, + v: { + type: 'boolean', + 'default': false + }, + fullId: { + type: 'boolean', + 'default': false, + name: 'full_id' + } + }, + url: { + fmt: '/_cat/thread_pool' + } +}); + /** * Perform a [clearScroll](http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/search-request-scroll.html) request * diff --git a/src/lib/apis/master.js b/src/lib/apis/master.js index 277a11c03..c6459b892 100644 --- a/src/lib/apis/master.js +++ b/src/lib/apis/master.js @@ -565,6 +565,48 @@ api.cat.prototype.shards = ca({ ] }); +/** + * Perform a [cat.threadPool](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat-thread-pool.html) request + * + * @param {Object} params - An object with parameters used to carry out this action + * @param {Boolean} params.local - Return local information, do not retrieve the state from master node (default: false) + * @param {Date, Number} params.masterTimeout - Explicit operation timeout for connection to master node + * @param {String, String[], Boolean} params.h - Comma-separated list of column names to display + * @param {Boolean} params.help - Return help information + * @param {Boolean} params.v - Verbose mode. Display column headers + * @param {Boolean} params.fullId - Enables displaying the complete node ids + */ +api.cat.prototype.threadPool = ca({ + params: { + local: { + type: 'boolean' + }, + masterTimeout: { + type: 'time', + name: 'master_timeout' + }, + h: { + type: 'list' + }, + help: { + type: 'boolean', + 'default': false + }, + v: { + type: 'boolean', + 'default': false + }, + fullId: { + type: 'boolean', + 'default': false, + name: 'full_id' + } + }, + url: { + fmt: '/_cat/thread_pool' + } +}); + /** * Perform a [clearScroll](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-request-scroll.html) request * diff --git a/src/lib/connectors/http.js b/src/lib/connectors/http.js index 2e7660cf5..8a0d65f7d 100644 --- a/src/lib/connectors/http.js +++ b/src/lib/connectors/http.js @@ -57,17 +57,21 @@ _.inherits(HttpConnector, ConnectionAbstract); HttpConnector.prototype.onStatusSet = _.handler(function (status) { if (status === 'closed') { - this.agent.minSockets = this.agent.maxSockets = 0; + var agent = this.agent; + agent.minSockets = agent.maxSockets = 0; + agent.requests = {}; - _.each(this.agent.sockets, function (sockets) { + _.each(agent.sockets, function (sockets, group) { _.each(sockets, function (s) { - s.destroy(); + s && agent.removeSocket(s, group); + s && s.destroy(); }); }); - _.each(this.agent.freeSockets, function (sockets) { + _.each(agent.freeSockets, function (sockets, group) { _.each(sockets, function (s) { - s.destroy(); + s && agent.removeSocket(s, group); + s && s.destroy(); }); }); } diff --git a/test/fixtures/keepalive.js b/test/fixtures/keepalive.js index 39affd68f..a70479865 100644 --- a/test/fixtures/keepalive.js +++ b/test/fixtures/keepalive.js @@ -1,5 +1,7 @@ var elasticsearch = require('../../src/elasticsearch'); var _ = require('lodash'); +var clock = require('sinon').useFakeTimers(); + var es = elasticsearch.Client({ host: 'localhost:5555', log: false @@ -16,6 +18,14 @@ es.search({ }, function (err, resp) { var conn = _.union(es.transport.connectionPool._conns.dead, es.transport.connectionPool._conns.alive).pop(); es.close(); + + if (_.size(clock.timeouts)) { + console.log('Timeouts were left behind'); + console.log(clock); + } + + clock.restore(); + var destroyedSockets = 0; function countDestroyed(sockets) { destroyedSockets += _.where(sockets, { destroyed: true}).length; @@ -23,4 +33,6 @@ es.search({ _.each(conn.agent.sockets, countDestroyed); _.each(conn.agent.freeSockets, countDestroyed); console.log(destroyedSockets); -}); \ No newline at end of file +}); + +clock.tick(1); \ No newline at end of file diff --git a/test/unit/specs/http_connector.js b/test/unit/specs/http_connector.js index 4059638c9..54b9c36c2 100644 --- a/test/unit/specs/http_connector.js +++ b/test/unit/specs/http_connector.js @@ -371,7 +371,7 @@ describe('Http Connector', function () { describe('Connection cleanup', function () { it('destroys any connections created', function (done) { - this.timeout(1000); + this.timeout(4000); var cp = require('child_process'); var path = require('path'); var es = require('event-stream');