Skip to content

Conversation

@adam-fowler
Copy link
Contributor

@adam-fowler adam-fowler commented Dec 15, 2025

If a connection fails then only that connection is allowed to retry to connect. All other connections on failure will be removed. This leads us to the situation where if we return to the running state from the failed connection state we could have a large request queue being served by only the one successful connection.

This PR ensures at least the minimum number of connections are created on returning to the running state. On top of this if the number of requests is greater than the number of streams a new connection will be created.

@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

❌ Patch coverage is 85.71429% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.99%. Comparing base (7383207) to head (d883b9b).

Files with missing lines Patch % Lines
Sources/ConnectionPoolModule/ConnectionPool.swift 16.66% 5 Missing ⚠️
...ources/ConnectionPoolModule/PoolStateMachine.swift 97.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #612      +/-   ##
==========================================
+ Coverage   75.88%   75.99%   +0.10%     
==========================================
  Files         134      134              
  Lines       10098    10135      +37     
==========================================
+ Hits         7663     7702      +39     
+ Misses       2435     2433       -2     
Files with missing lines Coverage Δ
...nPoolModule/PoolStateMachine+ConnectionGroup.swift 89.97% <100.00%> (+0.29%) ⬆️
...ources/ConnectionPoolModule/PoolStateMachine.swift 89.05% <97.14%> (+0.75%) ⬆️
Sources/ConnectionPoolModule/ConnectionPool.swift 92.85% <16.66%> (-2.10%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

let leaseResult = self.connections.leaseConnection(at: index, streams: UInt16(requests.count))
let connectionsRequired: Int
if requests.count <= self.connections.stats.availableStreams + self.connections.stats.leasedStreams {
connectionsRequired = self.configuration.minimumConnectionCount - Int(self.connections.stats.active)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does active include already connecting?

) -> Action {
// this connection was busy before
let requests = self.requestQueue.pop(max: availableContext.info.availableStreams)
if !requests.isEmpty {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what happens, if we have min connections = 5, but are coming out of circuit breaker and don't have anything in the queue?

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh this handled down below, once we have checked the pool state.

cancelledTimers: TinyFastSequence<TimerCancellationToken>,
scheduledTimers: Max2Sequence<Timer>
) -> ConnectionAction? {
if connectionCount > 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets use a guard here, instead.

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