swift-server / swift-server/async-http-client
AHC causes uncleanShutdown error on server side.
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 1.1k
- Forks
- 156
- PR merge metrics
- No merged PRs in 30d
Description
I have a server that is functionally similar in setup to hummingbird-examples/http2, when I use async-http-client to make a request with a command line program that exits after the request, humming bird reports this error:
[HummingbirdHTTP2] Error handling inbound connection for HTTP2 handler: uncleanShutdown
I do not see the same error when using curl:
curl --cacert certs/ca.crt --http2 -v https://localhost:8043/healthcheck
var tlsConfiguration: TLSConfiguration {
get throws {
let certificateChain = try NIOSSLCertificate.fromPEMFile(self.certificateChain)
var tlsConfiguration = TLSConfiguration.makeClientConfiguration()
tlsConfiguration.trustRoots = .certificates(certificateChain)
#if os(macOS)
tlsConfiguration.certificateVerification = .none
#else
// not supported with Network.framework
tlsConfiguration.certificateVerification = .noHostnameVerification
#endif
return tlsConfiguration
}
}
relevant code in the run() async throws method of an AsyncParsableCommand:
var clientConfig = HTTPClient.Configuration()
clientConfig.tlsConfiguration = try self.tlsConfiguration
try await HTTPClient.withHTTPClient(configuration: clientConfig) { client in
var request = HTTPClientRequest(url: url.absoluteString)
request.method = .POST
request.headers.add(name: "content-type", value: "application/json")
request.headers.add(name: "content-length", value: "\(payloadData.count)")
request.body = .bytes(payloadData)
let response = try await client.execute(request, timeout: .seconds(30))
let body = try await response.body.collect(upTo: 10 * 1024 * 1024)
}
I've tried many variations that all execute await client.shutdown() before exiting and they all result in this error. From what Cory says here: https://forums.swift.org/t/niossl-spurious-uncleanshutdown-error/53031/3 it seems like AHC isn't sending CLOSE_NOTIFY on shutdown?
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
Reproduce the report using the hummingbird-examples/http2 server and the AsyncParsableCommand run() async throws client code shown, then compare it with the curl request. Trace client shutdown and TLS handling around HTTPClient.withHTTPClient and client.shutdown(), focusing on whether the connection sends CLOSE_NOTIFY. Done means the request can complete and the command can exit without the server reporting uncleanShutdown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100