-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: master
Are you sure you want to change the base?
Conversation
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.
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 :)
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. |
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.
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?
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.
Yes, it's intentional. I think graceful exit means finishing all queries called before end, so I make that happen.
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.
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.
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.
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) { |
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.
Please add documentation for the new queued argument.
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 queued argument is a private argument, is it appropriate to add documentation to README.md?
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.
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.
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.
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.
Sorry to fix late, and a test case as you requested was added. |
946727b
to
37fbbdd
Compare
I'd love to see this feature. Any progress on that? |
@dougwilson I updated the Readme.md because of conflicts. So is there any chance to merge this pr? |
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. |
Hi @dougwilson I added the option to PoolCluster.end. And should I add the option to PoolCluster.remove too? |
As we discussed at #1803, this pull request adds an option to pool's creation,
If
gracefulExit
istrue
, everypool.getConnection
orpool.query
called beforepool.end
will success. Iffalse
, only commands / queries already in progress will complete, others will throw an error.