Skip to content
This repository has been archived by the owner on Dec 30, 2019. It is now read-only.

Fix two races #109

Merged
merged 1 commit into from
Dec 14, 2018
Merged

Fix two races #109

merged 1 commit into from
Dec 14, 2018

Conversation

johanneswuerbach
Copy link
Contributor

@johanneswuerbach johanneswuerbach commented Dec 2, 2018

Fix two races

  1. can occur after any connection failure as another _pulseQueue is never started and pending items added during the connect won't be processed

  2. occurs when a formerly queued client is processed and finds a free pool slot (e.g. because a previous client errored), but during client.connect times out itself.

@kibertoad
Copy link

@johanneswuerbach Tests are failing...

@johanneswuerbach
Copy link
Contributor Author

Added a fix for the second race.

@charmander
Copy link
Collaborator

charmander commented Dec 3, 2018

Can you explain the second one a little more? I’ve copied the simpler first one into a pull request at #111 in case it can go in earlier.

@johanneswuerbach
Copy link
Contributor Author

johanneswuerbach commented Dec 3, 2018

@charmander the issue occurs when you use connectionTimeoutMillis and in the following situation:

  1. connect call A starts connecting to the DB
  2. connect call B received between A and successful DB connection is being queued
  3. the db connection of call A fails with an error
  4. connect call B is pulsed in, finds a free-slot and attempts a database connection
  5. connect call B is timed out by connectionTimeoutMillis and a failure returned to the client
  6. the db connection of B is ready and the callback of connect call B called a 2nd time

My fix now creates a pendingItem object, which remembers the callback + timed out state and directly adds the new client to the idle queue in step 6 when the pending item already timed out.

}
if (!this._isFull()) {
return this.connect(waiter)
Copy link
Contributor Author

@johanneswuerbach johanneswuerbach Dec 3, 2018

Choose a reason for hiding this comment

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

I found re-entering into "full" connect here a bit confusing as we already know that we need to create a new client and can never add the waiter to the pending queue again as far as I can see.

Now this makes it more clear by using the newClient method directly here and in connect, wdyt?

@charmander
Copy link
Collaborator

Thanks for the explanation!

@vitaly-t
Copy link

vitaly-t commented Dec 6, 2018

When will we see this merged?

@johanneswuerbach
Copy link
Contributor Author

johanneswuerbach commented Dec 13, 2018

@brianc any chance you could have a look? Happy to rebase, but I would prefer a general 👍 / 👎 first.

@brianc
Copy link
Owner

brianc commented Dec 14, 2018

I think this looks good! Thanks for the explanation and PR! If you rebase I'll npm-link it into pg and make sure the tests pass over there as well (they should, they don't exercise the pool as much as these do, but wanna be sure) and if everything looks good I'll release a new patch version.

@johanneswuerbach
Copy link
Contributor Author

@brianc done 👍

@johanneswuerbach
Copy link
Contributor Author

Let me also know, if you think #110 is worth-while proceeding :-)

@brianc
Copy link
Owner

brianc commented Dec 14, 2018

K - tested this w/ node-postgres. All is in order. Will release a new patch version shortly. Thanks again!

@brianc brianc merged commit 35a285c into brianc:master Dec 14, 2018
@vitaly-t
Copy link

vitaly-t commented Dec 22, 2018

@brianc Christmas-shortly by any chance? 😄 Throw it under the Christmas tree, will ya? 😄

@brianc
Copy link
Owner

brianc commented Dec 22, 2018

Ah crap i totally forgot to release this after i tested. Will do! Sorry!

@vitaly-t
Copy link

vitaly-t commented Jan 1, 2019

When will it be? :)

@rdlowrey
Copy link

rdlowrey commented Jan 1, 2019

bump for great justice.

Really appreciate all the hard work on the library -- this one's definitely impacting us in production. New tagged release would be 💯

Thank you!

@brianc
Copy link
Owner

brianc commented Jan 2, 2019

yeah...sorry again. Was out of town. release [email protected]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants