-
Notifications
You must be signed in to change notification settings - Fork 2.5k
release pool connection restores pool user configuration #837
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
release pool connection restores pool user configuration #837
Conversation
restore a connections credentials before being returned to the pool if the connection had changeUser called on it
Great! This is almost complete. It still needs to make sure that session state added in |
Assuming I understood correctly that's done. However a Connections emit 3 types of event, I guess I could clear those listeners in |
I'm not sure. The essence is that if a user does this: pool.on('connection', function(conn) {
conn.query('SET time_zone = "+00:00"')
}) That session state must be done on any connection that comes from |
The PR now covers that scenario, but I notice that the tests are failing with node 0.8. I'll try to pick this up over the weekend as it's getting late here. An alternative would be to have a resetConnection event on the pool which a consumer could listen on to achieve the same thing, but with possibly clearer intent. |
Yes, but that wouldn't be backwards-compatible and would delay this until whenever 3.0 came around :) To land in 2.x, it has to work with existing 2.x code :) |
It's possible it just happened to fail on 0.8 because the modifications to the test just introduced some kind of race condition, rather than it not being compatible. You may need to look closer at possible race conditions in the test. |
Point well made ;) I'll investigate the tests then check to see if the readme needs modifying then get back to you. |
@@ -23,13 +23,44 @@ PoolConnection.prototype.changeUser = function changeUser(options, callback) { | |||
return __changeUser.apply(this, arguments); | |||
}; | |||
|
|||
PoolConnection.prototype.restoreUser = function restoreUser(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 entire routine needs to be moved into the Pool
. This is because restoring a user is a pool operation, not a connection operation. A user calling conn.restoreUser()
doesn't make any sense.
maybe node 0.8 emits after nextTick whereas 0.10 is calling emit immediately
Yo @dougwilson I think this may be ready now. I moved the method onto Pool as request, fixed the test (looked to me like emit calling listeners happens async in 0.8 - best guess without looking) and update the readme and changes. |
@seangarner thanks for the ping :) It looks great. I will likely have it merged tomorrow some time :D |
17209da
to
76de66e
Compare
closes mysqljs#1037 closes mysqljs#1038
restore a connections credentials before being returned to the pool if the connection had changeUser called on it
superseded by #1088. /me makes a note to himself to find out how the rebase went so wrong |
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 releasechangeUser
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.