-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client modifies configuration object such that it cannot be used again #33
Comments
I agree that this is bad. Working on a fix |
Sweet, thanks! |
Ok, started implementing this but I've decided against it. It sounds like a good idea on the surface but the configuration is very flexible and can regularly contain objects that shouldn't be cloned (loggers, transports, etc.). The specific objects that shouldn't be cloned couldn't be defined either, since it is completely legal for users to override certain classes and therefore the config they require. Because of this, it makes more sense to say that the config object belongs to the Client once it is sent in. I'd suggest making your config in a function and then passing the result into the client constructor: function config() {
return {
log: "warning"
};
}
var es1 = new elasticsearch.Client(config());
var es2 = new elasticsearch.Client(config()); |
The docs should probably highlight this. |
@gabegorelick you got it. I added a warning to the top of the configuration section. http://www.elasticsearch.org/guide/en/elasticsearch/client/javascript-api/current/configuration.html |
Awesome. Hopefully you won't get any more bug reports about it now. On Saturday, March 29, 2014, spenceralger notifications@github.com wrote:
|
IMHO, the library itself should duplicate the object passed when initializing to avoid the hassle of doing so to the implementer. |
@julien51 I had that opinion originally, but as stated earlier it's not really an option. |
…nt creation see elastic#33 (comment) Signed-off-by: Chris Dituri <csdituri@gmail.com>
* tracer package * configure package and webpack for distribution * separate logEntry and formatEntry; send entry to elastic * shallow copy elastic.Client options because elastic/elasticsearch-js#33 * add API docs to readme * adjust readme * Update README.md * configure frontend to work with trace data in elasticsearch * add circleci config * Update README.md * move elastic call to componentDidMount * move jest.json to root and only call test once in circle * remove fast-async * run packages/tracer/yarn install in circle * try different syntax for circle deps
* tracer package * configure package and webpack for distribution * separate logEntry and formatEntry; send entry to elastic * shallow copy elastic.Client options because elastic/elasticsearch-js#33 * add API docs to readme * adjust readme * Update README.md * configure frontend to work with trace data in elasticsearch * add circleci config * Update README.md * move elastic call to componentDidMount * move jest.json to root and only call test once in circle * remove fast-async * run packages/tracer/yarn install in circle * try different syntax for circle deps * Add basic functional analytics frontend * Remove superfluous curly braces from App.js
* tracer package * configure package and webpack for distribution * separate logEntry and formatEntry; send entry to elastic * shallow copy elastic.Client options because elastic/elasticsearch-js#33 * add API docs to readme * adjust readme * Update README.md * configure frontend to work with trace data in elasticsearch * add circleci config * Update README.md * move elastic call to componentDidMount * move jest.json to root and only call test once in circle * remove fast-async * run packages/tracer/yarn install in circle * try different syntax for circle deps * Add basic functional analytics frontend * Remove superfluous curly braces from App.js * Swap metrics and query columns
* tracer package * configure package and webpack for distribution * separate logEntry and formatEntry; send entry to elastic * shallow copy elastic.Client options because elastic/elasticsearch-js#33 * add API docs to readme * adjust readme * Update README.md * configure frontend to work with trace data in elasticsearch * add circleci config * Update README.md * move elastic call to componentDidMount * move jest.json to root and only call test once in circle * remove fast-async * run packages/tracer/yarn install in circle * try different syntax for circle deps * Add basic functional analytics frontend * Remove superfluous curly braces from App.js * Swap metrics and query columns * Organize and add documentation * Fix README anchoring/linking * Fix README linking * Use instead of as default index name
Create shallow copy of elasticsearch config to prevent: Unhandled rejection Error: Do not reuse objects to configure the elasticsearch Client class: elastic/elasticsearch-js#33 at new Client (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\elasticsearch\src\lib\client.js:38:11) at Object.create_es_client (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\express-cassandra\lib\orm\apollo.js:111:22) at Object._assert_es_index (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\express-cassandra\lib\orm\apollo.js:116:25) at Object.tryCatcher (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\bluebird\js\release\util.js:16:23) at Object.ret [as assertESIndexAsync] (eval at makeNodePromisifiedEval (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\bluebird\js\release\promisify.js:184:12), <anonymous>:13:39) at Object.onUserDefinedAggregates (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\express-cassandra\lib\orm\apollo.js:407:37) at Object._assert_user_defined_aggregates (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\express-cassandra\lib\orm\apollo.js:318:7) at Object.f (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\express-cassandra\lib\orm\apollo.js:426:14) at Object._assert_user_defined_functions (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\express-cassandra\lib\orm\apollo.js:253:7) at Object.f (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\express-cassandra\lib\orm\apollo.js:438:14) at Object._assert_user_defined_types (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\express-cassandra\lib\orm\apollo.js:201:7) at Object.f (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\express-cassandra\lib\orm\apollo.js:451:14) at C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\express-cassandra\lib\orm\apollo.js:190:9 at HostConnectionPool.next (C:\Users\mtsaren\Documents\GitHub\facenet\server\node\node_modules\cassandra-driver\lib\utils.js:503:5) at Object.onceWrapper (events.js:313:30) at emitNone (events.js:106:13)
Note that this pattern works:
|
Some observations: There are two elasticsearch packages in npm worth looking at, 'elasticsearch' and '@elastic/elasticsearch'. The second is meant to replace the first, but mongoose-elasticsearch-xp which will handle the replication of models apparently uses clients from the first. Further down the line we can test if '@elastic/elasticsearch' and be used instead. The elasticsearch client is uncaptured. Use makeConfig() to prevent future issues: See elastic/elasticsearch-js#33
For anyone doing unit testing in the NestJS context, freezing the config object in the module definition, prevents this error from firing repeatedly. Then the service can be mocked in unit tests.
|
When passing a config object to new elasticsearch.Client(), the Client modifies the passed in config object in such a way that it cannot be used to create a second client.
Example:
The text was updated successfully, but these errors were encountered: