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

Handle failure of ConnectionPool connection generator #137

Merged
merged 1 commit into from
May 30, 2018

Conversation

djones6
Copy link
Contributor

@djones6 djones6 commented May 25, 2018

Follows on from #128 and #103.

When the ConnectionPool is first created but the database is unreachable, it can fail to generate connections (if the generator has been written in such a way that only 'good' connections are returned).

In this scenario, the pool's current capacity (the initial number of connections we try to generate) is out of sync with the actual size of the pool (represented by pool.count), which is normally only the case when connections have been vended from the pool and not yet returned. We cannot recover from this situation, as we will not attempt to grow the pool, as its capacity is (apparently) not zero.

This fix ensures that the initial capacity and pool.count are in sync immediately after connection generation. We will attempt to generate a new connection each time we are asked to vend one, and this will continue to fail (and the capacity remain zero) while the database is unreachable. At some future time, if the database were to become reachable again, we will be at zero capacity and begin to grow the pool, as per #128.

Testing

I've verified that this resolves the ability to grow the pool after initial failure using a local project with a Postgres database and a connection generator function that only produces connections if they successfully connect().

@djones6 djones6 requested a review from DunnCoding May 25, 2018 10:08
@codecov-io
Copy link

Codecov Report

Merging #137 into master will decrease coverage by 0.14%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #137      +/-   ##
==========================================
- Coverage   84.47%   84.33%   -0.15%     
==========================================
  Files          43       43              
  Lines        3607     3613       +6     
==========================================
  Hits         3047     3047              
- Misses        560      566       +6
Flag Coverage Δ
#SwiftKuery 84.33% <0%> (-0.15%) ⬇️
Impacted Files Coverage Δ
Sources/SwiftKuery/ConnectionPool.swift 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 19ff072...9bdfb41. Read the comment docs.

@djones6 djones6 merged commit 46e93c2 into master May 30, 2018
@djones6 djones6 deleted the handleGenFailure branch May 30, 2018 10:38
@DunnCoding DunnCoding removed their request for review June 3, 2018 07:13
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.

3 participants