We have found that a server that is async-waiting after receiving a HTTP request does not see a CancellationError if the client were to close the connection.
This is trivially reproducible.
Server code:
let logger = Logger(label: "TestHTTPServer")
let server = NIOHTTPServer(logger: logger, configuration: .init(bindTarget: .hostAndPort(host: "127.0.0.1", port: 12345)))
try await server.serve { request, requestContext, requestBodyAndTrailers, responseSender in
print("STALLING...")
try await Task.sleep(for: .seconds(60 * 60))
}
Client terminal:
$ curl -v http://localhost:12345/stall
* Host localhost:12345 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:12345...
* connect to ::1 port 12345 from ::1 port 57145 failed: Connection refused
* Trying 127.0.0.1:12345...
* Connected to localhost (127.0.0.1) port 12345
> GET /stall HTTP/1.1
> Host: localhost:12345
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
^C
Server output:
The server hangs even though the client has closed the socket. Note how there is no exception or additional printing in the server output.
We have found that a server that is async-waiting after receiving a HTTP request does not see a
CancellationErrorif the client were to close the connection.This is trivially reproducible.
Server code:
Client terminal:
Server output:
The server hangs even though the client has closed the socket. Note how there is no exception or additional printing in the server output.