-
Notifications
You must be signed in to change notification settings - Fork 125
AsyncHTTPClient Transaction StateMachine Fatal Error with large Response Bodies #612
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
Comments
Hi Reid, thank you for the bug report! Haven't tried to reproduce it myself but this should definitely not happen! Do you have any URL you could share where this reproduces? Looking at the code, I think we hit a race condition where we cancel the request because we have received too many bytes but still receive some bytes from the connection afterwards. The fix could be as easy as tolerating more bytes while in the executing but finished state. That being said, I want to take a closer look as I'm suspecting we shouldn't even be in the executing but finished state after the request was canceled. |
Hi David, the test URL I used to produce the fatal error was |
Just for reference a full test case: let client = HTTPClient(eventLoopGroupProvider: .createNew)
defer { XCTAssertNoThrow(try client.syncShutdown()) }
var request = HTTPClientRequest(url: "http://api.weather.gov/zones/forecast/AKZ026/forecast")
request.headers.add(name: "User-Agent", value: "Swift HTTPClient")
let response = try await client.execute(request, deadline: .now() + .seconds(10))
let maxBodySize = 1024 * 1024
await XCTAssertThrowsError(try await response.body.collect(upTo: maxBodySize)) { error in
XCTAssert(error is NIOTooManyBytesError)
}
// we need to wait a bit to receive more packets before we shutdown the HTTPClient
try await Task.sleep(nanoseconds: UInt64(TimeAmount.milliseconds(100).nanoseconds)) Note that the URL only responds correctly if a |
Uh oh!
There was an error while loading. Please reload this page.
When function
try await response.body.collect(upTo: maxBodySize)
is called where response is aHTTPClientResponse
and maxBodySize = 1048576 (i.e 1 MB) and the response body is greater than 1MB then AsyncHTTPClient/Transaction+StateMachine fatal errors. I would expect that the function to throw but I wouldn't expect the fatal error.example code:
This is the error I am seeing
The text was updated successfully, but these errors were encountered: