-
Notifications
You must be signed in to change notification settings - Fork 120
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
Fix crash for large HTTP request headers #661
Fix crash for large HTTP request headers #661
Conversation
Motivation We currently don't handle large headers well which trigger a channel writability change event. Modification Add failing (but currently skipped) tests which reproduces the issue Result We can reliably reproduce the large request header issue in an integration and unit test. Note that the actual fix is not included to make reviewing easier and will come in a follow up PR.
Fix crash for when sending HTTP request headers result in a channel writability change event
# Conflicts: # Sources/AsyncHTTPClient/ConnectionPool/HTTP1/HTTP1ClientChannelHandler.swift # Sources/AsyncHTTPClient/ConnectionPool/HTTP1/HTTP1Connection.swift # Tests/AsyncHTTPClientTests/HTTPClientTests+XCTest.swift # Tests/AsyncHTTPClientTests/HTTPClientTests.swift
# Conflicts: # Tests/AsyncHTTPClientTests/HTTP2ClientRequestHandlerTests.swift # Tests/AsyncHTTPClientTests/HTTPClientTests.swift
|
||
self.request!.requestHeadSent() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this force-unwrap safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment
|
||
self.request!.requestHeadSent() | ||
if resumeRequestBodyStream { | ||
self.request!.resumeRequestBodyStream() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relatedly, why is this safe? Can it end up nil
after the preceding outcall?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! This is not safe. I added a test which crashed previously bit is fixed by chaining the implantation to unwrap safely: 18f6505
Sources/AsyncHTTPClient/ConnectionPool/HTTP2/HTTP2ClientRequestHandler.swift
Show resolved
Hide resolved
@swift-server-bot test this please |
Motivation
Fixes tests added in #658 and #659
Modification
Gracefully handle writability change events while headers are send.
Result
Large headers can be send. This could actually happen randomly for small headers too, especially in the HTTP/2 case. They just need to fill the buffer and trigger back pressure.