-
Notifications
You must be signed in to change notification settings - Fork 2.5k
switch user back to pool default on connection release #1088
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
switch user back to pool default on connection release #1088
Conversation
Couldn't reproduce the test failure locally with any of those versions of node, but guessing it's a race condition perhaps exposed by windows? Not sure. Anyways I've pushed a fix so hopefully the next ones pass. |
@dougwilson the test failing now is completely unrelated to these changes, and doesn't happen when I run the tests locally against that version of node. https://ci.appveyor.com/project/dougwilson/node-mysql/build/107/job/1vquubqcgptk422e#L219
I'm going to assume that this is ok to merge unless you say otherwise. |
Ok, so I just pushed a change to |
That test didn't fail the first time it ran: https://ci.appveyor.com/project/dougwilson/node-mysql/build/106/job/tjcdw1h46ll56nao#L234 And the only thing I changed in the last commit was an unrelated test. Perhaps it's intermittent? |
It's possible your change may have introduced some kind of race condition? I'm not sure, as I haven't taken a hard look at the changes. When running on AppVeyor, there is typically high latency, which really brings out issues in code and tests where you're relying on async events to trigger in specific orders, which is one of the reasons I test on there. |
}); | ||
connection._purge = false; | ||
} else { | ||
callback(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This callback needs to be in a process.nextTick
so that restoreUser
is always async instead of sometimes async.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for spotting that, fixed in 8b93ecb
Looks like that test failed on master, so you're changes are in the clear on that :) |
@dougwilson I've had a look at the travis failure and can't see how this change would have impacted that test. https://travis-ci.org/felixge/node-mysql/jobs/62480666#L457
If you disagree, I'd appreciate any suggestions on where to start looking. |
ha... I've just seen the latest master commit. I'll rebase this branch. |
42f8430
to
c458f83
Compare
@dougwilson tests are passing and I squashed the review comments ready for merge. |
Hi @dougwilson, I don't mean to pester; is there anything else you need me to do before this gets merged in? It'd be a shame to let it rot out in a PR again. |
Anything I can do to help get this merged? |
I'm working on merging this now. |
My biggest debate I've been having with myself is when we should call |
Also, would be nice to have a new test specifically testing this, rather then only updating an existing test to account for the change. |
@@ -38,17 +44,20 @@ server.listen(common.fakeServerPort, function(err) { | |||
|
|||
pool.getConnection(function(err, conn1) { | |||
assert.ifError(err); | |||
assert.strictEqual(conn1.threadId, 3); | |||
assert.ok(conn1.threadId === 1 || conn1.threadId === 2); | |||
assert.strictEqual(conn1.config.user, 'user_1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test needs to run the query SELECT CURRENT_USER()
to be sure the server-side actually got the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 8989512
Thanks for the feedback. Hoping to get time to start working on those changes later. |
c458f83
to
b64b547
Compare
The behaviour has changed from purging the connection from the pool, to switching user back to the pool config for the next time it's checked out. Perhaps it should be renamed? If not then some guidance on what the 2 separate tests are would be helpful. |
da76a2f
to
e45ab24
Compare
e45ab24
to
1fcba72
Compare
var config = connection.config; | ||
|
||
// only when credentials have been changed from the pool defaults | ||
if (config.user !== poolConfig.user || config.database !== poolConfig.database || config.password !== poolConfig.password || config.charset !== poolConfig.charset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no such thing as config.charset
, only config.charsetNumber
.
reincarnation of #837...
@dougwilson you said it was ready to merge last year, but I guess something more important came up and I forgot to bump on it. Would be good to get this change in.