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
Choose a base branch
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

Choose a reason for hiding this comment

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

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.
Copy link
Member

Choose a reason for hiding this comment

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

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?

Copy link
Author

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Please add documentation for the new queued argument.

Copy link
Author

Choose a reason for hiding this comment

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

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

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 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
Readme.md Outdated Show resolved Hide resolved
Copy link
Member

@dougwilson dougwilson left a comment

Choose a reason for hiding this comment

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

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.

@HQidea
Copy link
Author

HQidea commented Sep 24, 2017

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

@SpraxDev
Copy link

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

@HQidea
Copy link
Author

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

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 commented Jun 28, 2019

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

@kmaworld586

This comment was marked as spam.

@Ahmad45123

This comment was marked as spam.

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.

None yet

5 participants