Skip to content
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

Fix OOM issue when setting concurrentHTTP1ConnectionsPerHostSoftLimit to Int.max #763

Merged

Conversation

aryan-25
Copy link
Contributor

@aryan-25 aryan-25 commented Aug 8, 2024

Motivation:

When a user wishes to make the connection pool create as many concurrent connections as possible, a natural way to achieve this would be to set .max to the concurrentHTTP1ConnectionsPerHostSoftLimit property.

HTTPClient.Configuration().connectionPool = .init(
    idleTimeout: .hours(1),
    concurrentHTTP1ConnectionsPerHostSoftLimit: .max
)

The concurrentHTTP1ConnectionsPerHostSoftLimit property is of type Int. Setting it to Int.max leads to Int.max being passed as an argument to Arrays .reserveCapacity(_:) method, causing an OOM issue.

Addresses Github Issue #751

Modifications:

Capped the argument to self.connections.reserveCapacity(_:) to 1024 in HTTPConnectionPool.HTTP1Connections

Result:

Users can now set the concurrentHTTP1ConnectionsPerHostSoftLimit property to .max without causing an OOM issue.

…t` to `Int.max` in HTTPClient.Configuration.ConnectionPool
XCTAssertNoThrow(try httpClient.syncShutdown())
}

let response = httpClient.get(url: "https://localhost:\(bin.port)", deadline: .now() + .seconds(2))
Copy link
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.

@Lukasa Lukasa added the semver/patch For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label Aug 13, 2024
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Love this, very nice.

@fabianfett fabianfett merged commit 4b7a68e into swift-server:main Aug 14, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants