Skip to content

replace preconditions with errors #64

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

Closed
wants to merge 11 commits into from
Closed

Conversation

artemredkin
Copy link
Collaborator

@artemredkin artemredkin commented Jul 8, 2019

Will address #49 as well

Before this PR, channel.close was called after Task promise was fulfilled. This introduced a slight delay before receiving .end and closing the channel. This in turn could lead to a situation where we could receive .head right after .end, which is allowed by HTTP protocol (keep-alive) but is not currently supported (pending connection pool work) by ResponseAccumulator. In order to address this, we need to close channel immediately after receiving .end.

@artemredkin artemredkin added this to the 1.0.0 milestone Jul 8, 2019
@artemredkin artemredkin added the kind/bug Feature doesn't work as expected. label Jul 8, 2019
Copy link
Contributor

@ianpartridge ianpartridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It would be nice to have some tests which would have hit the preconditions and now catch a graceful failure.

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks great, thanks!

@artemredkin
Copy link
Collaborator Author

I'm trying to add a test, but it's not that straitforward :) NIO is pretty good at detecting when you do stupid things in your HTTPServerHandler :D

@artemredkin
Copy link
Collaborator Author

Test added

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I agree with this patch. SwiftNIO will never (and if it did that'd be a serious bug) send you anything but exactly 1 .head, 0... .body, 1 .end. This is hiding bugs and isn't actionable to the user.

What was the motivation for this?

@artemredkin
Copy link
Collaborator Author

@weissi see #49, we receive head, end, head in some cases, but it's correct in terms of http protocol I think, but HTTPResponseAccumulator cannot handle second response on the same connection, I will investigate why channel was not closed

@artemredkin
Copy link
Collaborator Author

@weissi I think channel.close happens too late, we receive .end and succeed the promise but callback (see line 358 in HTTPHandler.swift) on it's future is not called before we receive another channelRead, this is how we get into this inconsistent state.

@weissi
Copy link
Contributor

weissi commented Jul 23, 2019

@artemredkin cool, but that should be fixed then, no?

@artemredkin
Copy link
Collaborator Author

Question is, why task futureResult callback is called so late? It seems we need to call context.close right away in all cases

@artemredkin
Copy link
Collaborator Author

@weissi I reverted back to preconditions (preconditions in redirect handler will be replaced by #67), real issue was that we were closing channel too late, I propose to close channel immediately instead of relying on futureResult callback.

@weissi
Copy link
Contributor

weissi commented Jul 25, 2019

@artemredkin mind fixing the PR description and adding a good explanation of when exactly this will help? Also we definitely need a test case that proves this is effective.

@artemredkin
Copy link
Collaborator Author

@weissi done

@artemredkin
Copy link
Collaborator Author

This is not needed at all, underlying problem is solved by NIO:
https://github.com/apple/swift-nio/pull/1093/files

@artemredkin artemredkin closed this Aug 6, 2019
@artemredkin artemredkin deleted the remove_fatal_error branch August 6, 2019 17:57
@weissi
Copy link
Contributor

weissi commented Aug 9, 2019

@artemredkin released as swift-nio 2.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Feature doesn't work as expected.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants