Skip to content

change pool.end behavior, add force argument [breaking change, v9?] #2149

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

Closed
wants to merge 21 commits into from
Closed

change pool.end behavior, add force argument [breaking change, v9?] #2149

wants to merge 21 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 27, 2020

change pool.end([cb]) behavior, add force argument

  • process pending queries by default
  • allow optional force argument to drop pending queries

pool.end([force][, cb])

  it('pool.end() - finish pending queries by default', async () => {
    const pool = new Pool({ poolSize: 10 }) // pool size 10
    let completed = 0
    for (let x = 1; x <= 20; x++) { // queue up 20 queries
       pool.query('SELECT $1::text as name', ['brianc']).then(() => completed++)
    }
    await pool.end() // pool.end()
    expect(completed).to.equal(20) // all 20 queries finish
  })
  it('pool.end(true) - drop pending queries', async () => {
    const pool = new Pool({ poolSize: 10 }) // pool size 10
    let completed = 0
    for (let x = 1; x <= 20; x++) { // queue up 20 queries
       pool.query('SELECT $1::text as name', ['brianc']).then(() => completed++)
    }
    await pool.end(true) // pool.end(true)
    expect(completed).to.equal(10) // 10 active queries finish, 10 pending queries get dropped
  })

@ghost ghost mentioned this pull request Mar 27, 2020
Copy link
Owner

@brianc brianc left a comment

Choose a reason for hiding this comment

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

Thanks for the idea - I'm not going to be able to merge this unless you can write some pretty comprehensive tests covering the feature as well - anything I merge I'm responsible for maintaining indefinitely and without tests that burden is unbearable!

@ghost ghost changed the title add finish function change end behavior, add force argument Apr 1, 2020
@ghost ghost changed the title change end behavior, add force argument change pool.end behavior, add force argument Apr 2, 2020
@brianc
Copy link
Owner

brianc commented Apr 6, 2020

@brianc I tried running the existing tests on master branch for pg-pool and it is throwing require errors so Im not sure the existing tests are even working, pg-pool/test/ending.js is a single commit from 3 years ago?

the tests run in CI on every commit...I am preeeetty sure they're working. What commands exactly did you run & what was the output?

@ghost
Copy link
Author

ghost commented Apr 15, 2020

Ok I see in your Readme to use yarn test

@ghost ghost requested a review from brianc April 15, 2020 04:26
@ghost
Copy link
Author

ghost commented Apr 15, 2020

@brianc I am trying to write better test for you here but I am running into this bug I mentioned earlier brianc/node-pg-pool#134 it is throwing off my test to have pool.end complete before the last pool.query, any plans on fixing that?

Mike Slattery added 2 commits April 14, 2020 23:45
@ghost
Copy link
Author

ghost commented Apr 15, 2020

@brianc ok I wrote better tests. Only problem is that bug #2163 is causing this line to be 19 instead of 20 https://github.com/brianc/node-postgres/pull/2149/files#diff-57867471f03f2f65dd6fde482c6f9ea2R48 and this line to be 9 instead of 10 https://github.com/brianc/node-postgres/pull/2149/files#diff-57867471f03f2f65dd6fde482c6f9ea2R58

fix that bug then I will update this to 10 and 20 instead of 9 and 19

Mike Slattery added 2 commits April 14, 2020 23:51
@ghost ghost changed the title change pool.end behavior, add force argument change pool.end behavior, add force argument [breaking change] Apr 15, 2020
@ghost ghost changed the title change pool.end behavior, add force argument [breaking change] change pool.end behavior, add force argument [breaking change, v9?] Apr 15, 2020
@ghost ghost marked this pull request as draft April 16, 2020 19:15
@ghost ghost marked this pull request as ready for review April 16, 2020 19:16
@ghost
Copy link
Author

ghost commented May 9, 2020

Anyone have any thoughts on this PR? Anyone else think this should be the default behavior or is it just me? Also is this issue #2163 considered a bug that needs to be fixed? there are no comments on this PR or issue @brianc @charmander

@charmander
Copy link
Collaborator

Sure, I think it makes sense for this to be the default behaviour. Is force even necessary? I’m not sure when it would be the best solution to a problem.

@ghost
Copy link
Author

ghost commented May 10, 2020

I don't think I would ever use force but best to give the option of dropping pending queries to preserve the same functionality as previous pool.end for those that want it. Anyone feel free to update this PR with any changes

@ghost
Copy link
Author

ghost commented May 13, 2020

does this line also need to be updated? by changing this.ending to (this.ending && (!this._pendingQueue.length || this.force))

if (err || this.ending || !client._queryable || client._ending || client._poolUseCount >= this.options.maxUses) {

@charmander
Copy link
Collaborator

Since the author has deleted their account and can’t update the PR anymore, I’ll propose a version of this in a new one.

@charmander charmander closed this May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants