swift-server / swift-server/async-http-client
HTTPClient should fail early if the internet connection is offline or disconnects
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 1.1k
- Forks
- 156
- PR merge metrics
- No merged PRs in 30d
Description
Another big bump in a transition from URLSession to HTTPClient:
HTTPClient has no way of knowing the internet is offline or is disconnected. An executed request that hasn't connected will just result in a connection timeout, and a connected request that becomes disconnected during read/write will result in a read/write timeout, which with the shared singleton configuration is 90 seconds (!!!).
As a comparison, URLSession's default configuration causes a request to fail immediately with NSURLErrorNotConnectedToInternet unless waitsForConnectivity is set to true, in which case it then waits the full timeoutIntervalForRequest before failing, equivalent to AHC's Timeout.connect. No matter what waitsForConnectivity is set to, a disconnection from the internet during a connected request's read/write results in an immediate failure with NSURLErrorNetworkConnectionLost
I think URLSession's default behavior is quite sensible, and it would be great to offer an equivalent in AHC.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the HTTPClient behavior described in the issue and the shared configuration in Sources/AsyncHTTPClient/Configuration+BrowserLike.swift. Compare connection and read/write timeout handling with the URLSession behaviors linked in the report. Done means offline connections and disconnects during active requests fail promptly with behavior equivalent to the requested URLSession cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100