-
-
Notifications
You must be signed in to change notification settings - Fork 89
Ensure ConnectionPool.triggerForceShutdown() works and that it doesn't shutdown until all connections are closed
#607
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
Ensure ConnectionPool.triggerForceShutdown() works and that it doesn't shutdown until all connections are closed
#607
Conversation
ConnectionPool .triggerForceShutdown() works and that it doesn't shutdown until all connections are closedConnectionPool.triggerForceShutdown() works and that it doesn't shutdown until all connections are closed
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #607 +/- ##
==========================================
+ Coverage 75.68% 75.74% +0.05%
==========================================
Files 134 134
Lines 9912 10009 +97
==========================================
+ Hits 7502 7581 +79
- Misses 2410 2428 +18
🚀 New features to boost your workflow:
|
| } | ||
|
|
||
| @available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) | ||
| @Test func testForceShutdown() async throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a second test that tests, that we even close leased connections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, plus I added an extra test that ensure we shutdown correctly if a connection request is in progress
| index: Int, | ||
| availableContext: ConnectionGroup.AvailableConnectionContext | ||
| availableContext: ConnectionGroup.AvailableConnectionContext, | ||
| shuttingDown: Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not pass around shuttingDown here and instead rely on self.state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
| case shutdown(Shutdown) | ||
|
|
||
| case initiateShutdown(Shutdown) | ||
| case shutdown([TimerCancellationToken]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the difference between initiateShutdown and shutdown? can we add a developer comment here please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wanna rename this to cancelEventStreamAndFinalCleanup?
| case .idle(_, let newIdle): | ||
| if shuttingDown { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use a case ... where here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
fabianfett
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this is really, really great. Thanks so much for the improvements!
Now that we keep a record of all connections when shutting down it is possible for a connection to be released while in the closing state.
| case .backingOff, .starting, .idle, .closing, .closed: | ||
|
|
||
| case .closing: | ||
| return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we keep a record of all the connections during the shutdown It is now possible to catch a connection in the closing state when release is called after triggerForceShutdown
This PR fixes
ConnectionPool.triggerForceShutdown()so that it actually shuts down the connection pool and therun()method returns.I renamed the
shutdownconnection pool action toinitiateShutdownand added a new actionshutdown. TheinitiateShutdownaction will close all the connections and related timers and is returned bytriggerForceShutdown. Theshutdownaction will finish the eventStream thus allowing therunmethod to return. TheconnectionClosedmethod will return theshutdownaction once the connections array is empty. There is also support for dealing with connections that are established aftertriggerForceShutdownis called which wasn't there before.I have also added tests for the state machine, for when connections are idle, leased or a connection request is in process. And a single ConnectionPool test that checks
triggerForceShutdownactually causes therunmethod to return.Ensure
ConnectionPool.triggerForceShutdownworks and that it doesn't shutdown until all connections are closed