Skip to content

Creating a shallow copy of the config object for every connection created by the pool #805

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

Closed

Conversation

andrecardoso
Copy link

This prevents changing one connection's config object when other connections changes their config object (by changing its user, for example).

I had a problem with this because I'm using the connection's config.database property to know when to switch users.

…ated by the pool. This prevents changing one connection's config object when other connections changes their config object (by changing its user, for example).
@@ -35,7 +35,7 @@ Pool.prototype.getConnection = function (cb) {
}

if (this.config.connectionLimit === 0 || this._allConnections.length < this.config.connectionLimit) {
connection = new PoolConnection(this, { config: this.config.connectionConfig });
connection = new PoolConnection(this, { config: Util._extend({}, this.config.connectionConfig) });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.config.connectionConfig is a typed object; this extend destroys that typing. Please fix this.

@dougwilson
Copy link
Member

OK, I see what you mean. Because of https://github.com/felixge/node-mysql/blob/v2.2.0/lib/protocol/sequences/ChangeUser.js#L29-L32 .changeUser is basically incompatible with the pool. This solution is not a good one, as if you change user on a pooled connection and return it, now pool.getConnection may return a connection with a different context than the rest. Calling .changeUser on a pooled connection needs to also remove it from the pool.

@dougwilson dougwilson added the bug label May 5, 2014
@dougwilson dougwilson added this to the 2.3 milestone May 5, 2014
@dougwilson dougwilson self-assigned this May 5, 2014
@dougwilson dougwilson closed this in ea9a27c May 5, 2014
@andrecardoso
Copy link
Author

Should I have a pool for each user/database?

@dougwilson
Copy link
Member

Yes, if you are changing the user a lot. Each time you call .changeUser it is a lot of protocol overhead; so the call is not cheap. You also don't have to then worry about what user a connection will be when you get one from the pool, as they'll always be the same user.

@andrecardoso
Copy link
Author

Nice. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants