Skip to content

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

Closed

Conversation

seangarner
Copy link
Contributor

reincarnation of #837...

Discussed potential for this in #833 whereby a connection that is checked out from the pool then has changeUser called it would be marked for purging when it was released. Instead during release changeUser is called again to restore it back to the pool configuration before it's released back into the pool.

I've updated the test that covered restoreUser and all tests are passing locally, but I couldn't find a jshint or styleguide so I'm fully open to changes before merging.

@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.

@seangarner
Copy link
Contributor Author

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.

@seangarner
Copy link
Contributor Author

@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

test\unit\query\test-streaming-destroy.js

I'm going to assume that this is ok to merge unless you say otherwise.

@dougwilson
Copy link
Member

Ok, so I just pushed a change to master. If it fails, then yes, it has nothing to do with your PR. If it doesn't fail, then even though it doesn't seem like it, it would seem very likely something in the PR is causing the failure.

@seangarner
Copy link
Contributor Author

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?

@dougwilson
Copy link
Member

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();
Copy link
Member

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.

Copy link
Contributor Author

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

@dougwilson
Copy link
Member

Looks like that test failed on master, so you're changes are in the clear on that :)

@seangarner
Copy link
Contributor Author

@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

not ok 144 test/unit/query/test-streaming-destroy.js

  events.js:71
          throw arguments[1]; // Unhandled 'error' event
                         ^
  Error: This socket is closed.
      at Socket._write (net.js:519:19)
      at Socket.write (net.js:511:15)
      at FakeConnection.writeRow (/home/travis/build/felixge/node-mysql/test/FakeServer.js:389:18)
      at Timer.exports.setInterval.timer.ontimeout (timers.js:234:14)

If you disagree, I'd appreciate any suggestions on where to start looking.

@seangarner
Copy link
Contributor Author

ha... I've just seen the latest master commit. I'll rebase this branch.

@seangarner seangarner force-pushed the no-disconnect-on-changeUser-return branch 2 times, most recently from 42f8430 to c458f83 Compare May 14, 2015 16:34
@seangarner
Copy link
Contributor Author

@dougwilson tests are passing and I squashed the review comments ready for merge.

@seangarner
Copy link
Contributor Author

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.

@seangarner
Copy link
Contributor Author

Anything I can do to help get this merged?

@dougwilson
Copy link
Member

I'm working on merging this now.

@dougwilson
Copy link
Member

My biggest debate I've been having with myself is when we should call changeUser on the connection: when it is returned to the pool (like now), or when it is requested from the pool (in place of doing a ping on that connection).

@dougwilson
Copy link
Member

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');
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 8989512

@seangarner
Copy link
Contributor Author

Thanks for the feedback. Hoping to get time to start working on those changes later.

@seangarner seangarner force-pushed the no-disconnect-on-changeUser-return branch from c458f83 to b64b547 Compare July 2, 2015 17:03
@seangarner
Copy link
Contributor Author

would be nice to have a new test specifically testing this, rather then only updating an existing test to account for the change

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.

seangarner added a commit to dynamicaction/node-mysql that referenced this pull request Jul 3, 2015
@seangarner seangarner force-pushed the no-disconnect-on-changeUser-return branch 2 times, most recently from da76a2f to e45ab24 Compare July 3, 2015 21:31
@seangarner seangarner force-pushed the no-disconnect-on-changeUser-return branch from e45ab24 to 1fcba72 Compare July 3, 2015 21:33
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) {
Copy link
Member

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.

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