From 1dca3826259674dbeb715c580e947ef244108679 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Fri, 7 Feb 2014 14:00:05 -0700 Subject: [PATCH 1/4] turns out 1 second might not be enough --- test/unit/specs/http_connector.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/specs/http_connector.js b/test/unit/specs/http_connector.js index 4059638c9..ca9a0a202 100644 --- a/test/unit/specs/http_connector.js +++ b/test/unit/specs/http_connector.js @@ -371,7 +371,6 @@ describe('Http Connector', function () { describe('Connection cleanup', function () { it('destroys any connections created', function (done) { - this.timeout(1000); var cp = require('child_process'); var path = require('path'); var es = require('event-stream'); From e8067df259ba727d69114ec65275418523f662f5 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Mon, 10 Feb 2014 09:17:06 -0700 Subject: [PATCH 2/4] added the cat.threadPool method to the master/1.0/1.x apis --- docs/api_methods_1_0.asciidoc | 34 ++++++++++++++++++++++++++ docs/api_methods_1_x.asciidoc | 34 ++++++++++++++++++++++++++ docs/api_methods_master.asciidoc | 34 ++++++++++++++++++++++++++ src/lib/apis/1_0.js | 42 ++++++++++++++++++++++++++++++++ src/lib/apis/1_x.js | 42 ++++++++++++++++++++++++++++++++ src/lib/apis/master.js | 42 ++++++++++++++++++++++++++++++++ 6 files changed, 228 insertions(+) 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 * From 257d596207d689ba86e6814a52d2198cc2434db1 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Mon, 10 Feb 2014 13:34:02 -0700 Subject: [PATCH 3/4] attempting to diagnos random issues with the client.close() test --- src/lib/connectors/http.js | 14 +++++++++----- test/fixtures/keepalive.js | 12 +++++++++++- test/unit/specs/http_connector.js | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) 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..e9267784d 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,12 @@ 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); + } + var destroyedSockets = 0; function countDestroyed(sockets) { destroyedSockets += _.where(sockets, { destroyed: true}).length; @@ -23,4 +31,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 ca9a0a202..54b9c36c2 100644 --- a/test/unit/specs/http_connector.js +++ b/test/unit/specs/http_connector.js @@ -371,6 +371,7 @@ describe('Http Connector', function () { describe('Connection cleanup', function () { it('destroys any connections created', function (done) { + this.timeout(4000); var cp = require('child_process'); var path = require('path'); var es = require('event-stream'); From 77d934aa03b286a0eceee0d3a83b4d64431c4e01 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Mon, 10 Feb 2014 13:57:14 -0700 Subject: [PATCH 4/4] restore the clock before leaving the process to die --- test/fixtures/keepalive.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/fixtures/keepalive.js b/test/fixtures/keepalive.js index e9267784d..a70479865 100644 --- a/test/fixtures/keepalive.js +++ b/test/fixtures/keepalive.js @@ -24,6 +24,8 @@ es.search({ console.log(clock); } + clock.restore(); + var destroyedSockets = 0; function countDestroyed(sockets) { destroyedSockets += _.where(sockets, { destroyed: true}).length;