Fix sendability issues in the connection pool (#833)

Motivation:

The connection pool holds much of the low level logic in AHC. We should
fix its sendability issues before moving to higher levels.

Modifications:

- Make HTTP1ConnectionDelegate and HTTP2Delegate sendable, this requires
passing IDs rather than connections to their methods
- Make HTTPConnectionRequester sendable and have its methods take
Sendable views of the HTTP1Connection and HTTP2Connection types
- Add sendable views to HTTP1Connection and HTTP2Connection
- Mark HTTP1Connection and HTTP2Connection as not sendable
- Make HTTPRequestExecutor and HTTPExecutableRequest sendable
- Update tests

Result:

Connection pool has stricter sendability requirements
This commit is contained in:
George Barnett
2025-04-28 15:33:38 +01:00
committed by GitHub
parent 0e715a2793
commit 086524fd8a
16 changed files with 465 additions and 361 deletions
@@ -176,7 +176,7 @@ protocol HTTPSchedulableRequest: HTTPExecutableRequest {
/// A handle to the request executor.
///
/// This protocol is implemented by the `HTTP1ClientChannelHandler`.
protocol HTTPRequestExecutor {
protocol HTTPRequestExecutor: Sendable {
/// Writes a body part into the channel pipeline
///
/// This method may be **called on any thread**. The executor needs to ensure thread safety.
@@ -201,7 +201,7 @@ protocol HTTPRequestExecutor {
func cancelRequest(_ task: HTTPExecutableRequest)
}
protocol HTTPExecutableRequest: AnyObject {
protocol HTTPExecutableRequest: AnyObject, Sendable {
/// The request's logger
var logger: Logger { get }