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

Using half-closed connections in Http().serverLayer #94

Open
akka-ci opened this issue Sep 8, 2016 · 9 comments
Open

Using half-closed connections in Http().serverLayer #94

akka-ci opened this issue Sep 8, 2016 · 9 comments
Labels
1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted t:server Issues related to the HTTP server
Milestone

Comments

@akka-ci
Copy link

akka-ci commented Sep 8, 2016

Issue by Quizzie
Thursday Jan 07, 2016 at 12:55 GMT
Originally opened as akka/akka#19373


In Akka HTTP version 2.0.1 the Http().serverLayer doesn't work correctly. If one sends an HTTP request through the Http().serverLayer and then an HTTP response in the other direction, the stream completes before the response is passed through.

A demonstration is shown in this project: https://github.com/Quizzie/server-layer-bug
The bug.serverlayer.ServerLayerTest is a test which uses the Http().serverLayer as an HTTP parser.
The test in the master branch shows that it works correctly in Akka HTTP version 1.0.
The test in the version-2.0.1 branch shows that it breaks in Akka HTTP version 2.0.1 (the test fails).

@akka-ci akka-ci added this to the http-backlog milestone Sep 8, 2016
@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by ktoso
Thursday Jan 07, 2016 at 12:57 GMT


Thanks for reporting and the reproducer, will have a look soon.
// cc @sirthias @jrudolph

@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by jrudolph
Thursday Jan 07, 2016 at 15:10 GMT


@Quizzie you rely on a half-closed TCP connection (or stream in your case) to work with HTTP. This is currently not supported by akka-http.

I.e. it will not work to close the input byte stream before having received the response.

@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by MichaelZinsmaier
Friday Jan 08, 2016 at 09:06 GMT


After reading more about half-closed TCP and HTTP related Akka Client Ticket, 2001 W3C post, ...
I agree, the HTTP spec seems to be surprisingly vague regarding half closed connections

=> maybe its not a bug its a feature request (-:

justification

tldr. a type A HTTP server is more defensive and standalone usage of the serverLayer would benefit

From a HTTP perspective

If there are major HTTP server implementations that treat half close as abort client implementations should not depend on it (they should be type 2 like the Akka HTTP client)

  • however following the arguments from the 2001 W3C post a type A server would be more defensive (potentially with some performance cost)
  • Akka HTTP as integration layer might face some old/legacy/strange clients (in contrast to browsers / standard library based nice clients)
From a stream perspective:

The docs state that:

"... [the server Layer] can be useful ... to "run" the HTTP layer (and, potentially, higher-layers) against data that do not come from the network but rather some other source. Potential scenarios where this might be useful include tests, debugging or low-level event-sourcing (e.g by replaying network traffic)."

Ok lets assume I record HTTP requests into files and want to replay them later on. The problem is that there is no client application and thus no out of band knowledge about the number of responses I expect.

  • Scenario 1: I recorded one HTTP request
    Reading it in with a FileSource and plugging that into the ServerLayer would not work out of the box because complete would have to be delayed until the response has been received.
  • Scenario 2: I record two HTTP requests on a persisted connection
    This is more difficult because I somehow have to know that I want to see two responses. But all the HTTP data (nr of requests, potential CLOSE headers, ...) is only available after parsing => inside the serverLayer

=> I suggest either implementing the serverLayer as type A server or having a more low level API that splits up parsing and HTTP protocol handling (to be able to inject some custom code)

aside from that having a type B server is proably just fine in most cases (-:

Best Michael

@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by jrudolph
Friday Jan 08, 2016 at 09:44 GMT


I don't disagree with your assessment. I guess one reason we disabled it at some point is that figuring out closing conditions correctly is often quite hard and it's easy to create leaks this way.

@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by ktoso
Friday Jan 08, 2016 at 09:47 GMT


In any case – removing bug marker that that's cleared out.

@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by Quizzie
Friday Jan 08, 2016 at 10:10 GMT


Alright, let's consider this issue to be a feature request.
Should I close it or leave it open?

@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by ktoso
Thursday May 19, 2016 at 00:25 GMT


FYI, half closed stuff again @johanandren - WDYT?

@akka-ci
Copy link
Author

akka-ci commented Sep 8, 2016

Comment by johanandren
Thursday May 19, 2016 at 06:45 GMT


Not sure I have an opinion, seems hard to get right, and this one in particular probably won't cause problems for many people. Maybe just make sure to document that this is how it works, unless someone wants to contribute a solution?

@jrudolph jrudolph added the 1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted label Sep 8, 2016
@ktoso ktoso removed the t:http label Sep 12, 2016
@jrudolph jrudolph added t:server Issues related to the HTTP server and removed t:http:server labels Nov 2, 2016
@raboof
Copy link
Contributor

raboof commented Jul 15, 2020

More relevant upstream discussion: httpwg/http-core#22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted t:server Issues related to the HTTP server
Projects
None yet
Development

No branches or pull requests

4 participants