Handle failure of ConnectionPool connection generator #137
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 bypool.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()
.