-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Domains support #709
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
Domains support #709
Conversation
LGTM. I've never really worked with domains as they don't solve the problem of callback safety, but I'm all for it if people find them useful. |
@dresende @dougwilson - wdyt? |
It looks good to me. Do we think this should also be added to the callbacks in |
You are right. For some reason I was thinking that this is unnecessary. because already happens in underlying query call. I'll add this to pool callbacks |
@sidorares yea, I thought so too. It may, but at the very least |
@dougwilson - added test, but can't make it to fail, pooled connection seems to use correct domain. |
I think to see the pool fail, you have to have an idle connection in the pool, then calling getConnection will loose the domain. If getConnection actually creates a brand new connection then the domain stuff is covered by Connection methods. From: Andrey Sidorovmailto:[email protected] @dougwilson - added test, but can't make it to fail, pooled connection seems to use correct domain. Reply to this email directly or view it on GitHub: |
still not failing...
|
Yea, sorry, after I sent that I realized I said it wrong. I actually meant the domain will vanish when |
See if this fails, plz :) var pool = common.createPool({connectionLimit: 1});
pool.getConnection(function(err, conn) {
d3.run(function() {
pool.query('SELECT 2', function(err, _rows, _fields) {
if (err) throw err;
throw new Error('inside domain 3');
});
});
process.nextTick(function () {
conn.release();
});
}); |
If the above does fail, I think it would fix it by binding the domain to If it does not fail, then I guess we won't worry about it unless I can come with with something that does fail :) |
Finally - test fails without pool.js change and passes with. @dougwilson - could you please review the test? |
Sweet. I think we are good to go. I can't think of any other holes there would be. |
thanks for help @dougwilson - very much appreciated! merging... |
💖 thx guys |
This change is very similar to sidorares/node-mysql2#75
Usually connection/pool is created in top level domain (or no domain at all) and you would expect
query(cb)
callback to be called in the context ofquery()
domain (often http request level domain). Instead, connection EventEmitter captures connect time domain and it is used later in all callbacks. This PR wraps all api callbacks withbindToCurrentDomain
function. There should be no performance impact when domains are not used. See test and sidorares/node-mysql2#73 for code examples