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

Make ConnectionPool's retryConnectionEstablishment public #744

Merged
merged 8 commits into from
Jun 18, 2024

Conversation

andreasley
Copy link
Contributor

Currently, there is no way to instantly return when a connection attempt fails. The connection timeout is always awaited, regardless of the connection error. When used within a service, this behavior makes sense – network conditions may temporarily prevent establishing a connection. However, in a user-interactive environment, it's preferable to fail quickly and display the error to the user.

#625 introduced the property retryConnectionEstablishment, which defaults to true but can be set to false to not retry on connection failure. The property was added to speed up unit tests, but would also be suitable for the use-case mentioned above.

This PR makes the property retryConnectionEstablishment, which is already documented and well tested, public.

This would fix #743.

The PR also cleans up some unit tests to consistently use enableFastFailureModeForTesting() instead of setting retryConnectionEstablishment directly.

Questions:

  • When using NIOTS, the HTTPClient.Configuration's property networkFrameworkWaitForConnectivity also needs to be set to false to enable fast fail. Would it be worthwhile to have the ability to set both properties at once?

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.

Very nice, thank you! Just a single quick note.


public init(idleTimeout: TimeAmount = .seconds(60)) {
self.init(idleTimeout: idleTimeout, concurrentHTTP1ConnectionsPerHostSoftLimit: 8)
}

public init(idleTimeout: TimeAmount, concurrentHTTP1ConnectionsPerHostSoftLimit: Int) {
public init(idleTimeout: TimeAmount, concurrentHTTP1ConnectionsPerHostSoftLimit: Int, retryConnectionEstablishment: Bool = true) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unfortunately it's not API stable to add this extra parameter. Rather than us keep proliferating new inits, it might be nice for us to just add a zero-element initializer and encourage users towards setting the fields after default construction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking a look! I've...

  • Reverted the change to the existing initializer.
  • Added a parameterless initializer.
  • Removed the default value for the parameter idleTimeout in the respective initializer (because it overlaps with the new parameterless initializer). Is that safe in terms of API stability?
  • Moved the default values to the respective property declarations (to prevent them having to be specified at multiple points in the initializer code). This seems cleaner to me than initializer delegation, but if you prefer a different style, let me know.

@Lukasa
Copy link
Collaborator

Lukasa commented Jun 17, 2024

@swift-server-bot test this please

@Lukasa Lukasa added the semver/minor For PRs that when merged cause a bump of the minor version, ie. 1.x.0 -> 1.(x+1).0 label Jun 17, 2024
@Lukasa
Copy link
Collaborator

Lukasa commented Jun 18, 2024

@swift-server-bot test this please

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.

Basically fine, one quick note.

Sources/AsyncHTTPClient/HTTPClient.swift Outdated Show resolved Hide resolved
@fabianfett
Copy link
Member

@swift-server-bot test this please

@Lukasa
Copy link
Collaborator

Lukasa commented Jun 18, 2024

I'm ignoring API breakage here: it's concerned about us removing the default argument, but we've replaced it with a zero-argument constructor so it's safe from an API perspective.

@Lukasa Lukasa merged commit e27aef4 into swift-server:main Jun 18, 2024
5 of 7 checks passed
@andreasley andreasley deleted the feature-fastfail branch June 18, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor For PRs that when merged cause a bump of the minor version, ie. 1.x.0 -> 1.(x+1).0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Connection refused not throwing right away
3 participants