Skip to content
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

Merged
merged 21 commits into from
Feb 10, 2023

Conversation

dnadoba
Copy link
Collaborator

@dnadoba dnadoba commented Jan 25, 2023

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.

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
@dnadoba dnadoba added the 🔨 semver/patch No public API change. label Jan 25, 2023
# 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
@dnadoba dnadoba marked this pull request as ready for review January 26, 2023 13:29

self.request!.requestHeadSent()
Copy link
Collaborator

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?

Copy link
Collaborator Author

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()
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

@dnadoba dnadoba requested a review from Lukasa February 9, 2023 12:59
@Lukasa
Copy link
Collaborator

Lukasa commented Feb 9, 2023

@swift-server-bot test this please

@dnadoba dnadoba merged commit 1d24271 into swift-server:main Feb 10, 2023
@dnadoba dnadoba deleted the dn-fix-large-header-request branch February 10, 2023 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants