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 98.07692% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.09%. Comparing base (7383207) to head (d7bf5f9).

Files with missing lines Patch % Lines
Sources/ConnectionPoolModule/ConnectionPool.swift 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #612      +/-   ##
==========================================
+ Coverage   75.88%   76.09%   +0.21%     
==========================================
  Files         134      134              
  Lines       10098    10145      +47     
==========================================
+ Hits         7663     7720      +57     
+ Misses       2435     2425      -10     
Files with missing lines Coverage Δ
...nPoolModule/PoolStateMachine+ConnectionGroup.swift 89.70% <100.00%> (+0.02%) ⬆️
...ources/ConnectionPoolModule/PoolStateMachine.swift 89.24% <100.00%> (+0.93%) ⬆️
Sources/ConnectionPoolModule/ConnectionPool.swift 94.69% <87.50%> (-0.27%) ⬇️

... and 3 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

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.

var idleTimeoutDuration: Duration = .seconds(30)

@usableFromInline
var maximumConnectionRequestsAtOneTime: Int = 20
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should add a follow up pr that allows us to configure this after we have landed this pr.

Copy link
Collaborator

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

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

Amazing!

@adam-fowler
Copy link
Contributor Author

Fixed crash, testCopyFromHasWriteBackpressure is still failing occasionally but this is unrelated

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