Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ extension HTTPConnectionPool {

init(maximumConcurrentConnections: Int, generator: Connection.ID.Generator, maximumConnectionUses: Int?) {
self.connections = []
self.connections.reserveCapacity(maximumConcurrentConnections)
self.connections.reserveCapacity(min(maximumConcurrentConnections, 1024))
self.overflowIndex = self.connections.endIndex
self.maximumConcurrentConnections = maximumConcurrentConnections
self.generator = generator
Expand Down
19 changes: 19 additions & 0 deletions Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,25 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
}
}

func testInsanelyHighConcurrentHTTP1ConnectionLimitDoesNotCrash() throws {
let bin = HTTPBin(.http1_1(compress: false))
defer { XCTAssertNoThrow(try bin.shutdown()) }

var httpClientConfig = HTTPClient.Configuration()
httpClientConfig.connectionPool = .init(
idleTimeout: .hours(1),
concurrentHTTP1ConnectionsPerHostSoftLimit: Int.max
)
httpClientConfig.timeout = .init(connect: .seconds(10), read: .seconds(100), write: .seconds(100))

let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup), configuration: httpClientConfig)
defer {
XCTAssertNoThrow(try httpClient.syncShutdown())
}

let response = httpClient.get(url: "https://localhost:\(bin.port)", deadline: .now() + .seconds(2))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we need to use the async/await API here.

}

func testRedirectChangesHostHeader() {
XCTAsyncTest {
let bin = HTTPBin(.http2(compress: false))
Expand Down