The Wayback Machine - https://web.archive.org/web/20201101090525/https://github.com/mysqljs/mysql/pull/1810
Skip to content
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

feat: pool adds gracefulExit to end gracefully #1810

Open
wants to merge 6 commits into
base: master
from

Conversation

@HQidea
Copy link

@HQidea HQidea commented Aug 28, 2017

As we discussed at #1803, this pull request adds an option to pool's creation,

var pool = common.createPool({
  // ...
  gracefulExit: true
});

If gracefulExit is true, every pool.getConnection or pool.query called before pool.end will success. If false, only commands / queries already in progress will complete, others will throw an error.

Copy link
Member

@dougwilson dougwilson left a comment

A couple comments and looks like the coverage check failed because there are uncovered cose paths introduced in this change. If you need help coming up with a test at all, let me know and I can lend a hand :)

.gitignore Outdated Show resolved Hide resolved
Readme.md Outdated Show resolved Hide resolved
Readme.md Outdated
If `gracefulExit` is set to `true`, the connections end _gracefully_, so all
-pending queries will still complete and the time to end the pool will vary.

The default `gracefulExit` is `false`, the following behavior will take effect.

This comment has been minimized.

@dougwilson

dougwilson Aug 30, 2017
Member

I think the exact details of how the graceful end works here would be useful, as I remember that was the initial confusion here. As far as I can tell, this implementation will still let checked out connections queue new queries if there is at least one connection in the middle of being established, since the QUIT commands are not queued on all the connections until there is no connection in the aquiring state, is that intentional?

This comment has been minimized.

@HQidea

HQidea Sep 9, 2017
Author

Yes, it's intentional. I think graceful exit means finishing all queries called before end, so I make that happen.

This comment has been minimized.

@dougwilson

dougwilson Sep 10, 2017
Member

Right, but my comment was that your code is still sometimes allowing queries to be called after end. Is the call to end a hard stop, or should new queries still be allowed to get scheduled? The other issue is that under the acquiring condition, it will sometimes then stop the checked out connections from continuing to query and sometimes not.

This comment has been minimized.

@HQidea

HQidea Jun 25, 2019
Author

Right, but my comment was that your code is still sometimes allowing queries to be called after end. Is the call to end a hard stop, or should new queries still be allowed to get scheduled?

Only queries have been called before end would be allowed to execute, new queries after end would not be allowed no matter whether there is any checked out connection in the pool

The other issue is that under the acquiring condition, it will sometimes then stop the checked out connections from continuing to query and sometimes not.

When will the acquiring condition will happen?

lib/Pool.js Outdated
}

Pool.prototype.getConnection = function (cb) {
Pool.prototype.getConnection = function (cb, queued) {

This comment has been minimized.

@dougwilson

dougwilson Aug 30, 2017
Member

Please add documentation for the new queued argument.

This comment has been minimized.

@HQidea

HQidea Sep 9, 2017
Author

This queued argument is a private argument, is it appropriate to add documentation to README.md?

This comment has been minimized.

@dougwilson

dougwilson Sep 10, 2017
Member

There is no such thing as a private argument -- the user can simply pass in the value. Just not documenting it doesn't make it private. If the argument is there, it needs to be documented.

lib/Pool.js Outdated Show resolved Hide resolved
lib/Pool.js Show resolved Hide resolved
Readme.md Outdated Show resolved Hide resolved
Copy link
Member

@dougwilson dougwilson left a comment

Can you add at least one test that tests the issue you were having: in a pool of size n, have n connections already in use and then call pool.query so that is pending in the queue. Then call pool.end with the graceful and release those connections to let the pool.query get picked off the queue and ran even though .end was already called.

@dougwilson dougwilson added the feature label Sep 10, 2017
@HQidea
Copy link
Author

@HQidea HQidea commented Sep 24, 2017

Sorry to fix late, and a test case as you requested was added.

@dougwilson dougwilson force-pushed the mysqljs:master branch 2 times, most recently from 946727b to 37fbbdd Nov 16, 2018
@SpraxDev
Copy link

@SpraxDev SpraxDev commented Jun 22, 2019

I'd love to see this feature. Any progress on that?

@HQidea
Copy link
Author

@HQidea HQidea commented Jun 25, 2019

@dougwilson I updated the Readme.md because of conflicts. So is there any chance to merge this pr?
If you require any further information, please let me know.

@dougwilson
Copy link
Member

@dougwilson dougwilson commented Jun 25, 2019

Hi @HQidea I really apologize on this one. I looked over the state of the PR when @Sprax2013 commented trying to remember why it wasn't merged. I got to work and found the reason in some notes I had: I meant to update the PR to pass options through the PoolCluster, which wraps around Pool so they could utilize the new end options added here.

I completely lost track of that, and I'm sorry for that.

@HQidea
Copy link
Author

@HQidea HQidea commented Jun 28, 2019

Hi @dougwilson I added the option to PoolCluster.end. And should I add the option to PoolCluster.remove too?

@kmaworld586
Copy link

@kmaworld586 kmaworld586 commented Jul 1, 2019

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

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.