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

H2 Early Hints cannot be used with response streaming #32329

Closed
PikachuEXE opened this issue Mar 23, 2018 · 10 comments
Closed

H2 Early Hints cannot be used with response streaming #32329

PikachuEXE opened this issue Mar 23, 2018 · 10 comments

Comments

@PikachuEXE
Copy link
Contributor

PikachuEXE commented Mar 23, 2018

Steps to reproduce

Expected behavior

The response should NOT emit Early Hint lines during rendering with response streaming enabled

Actual behavior

Illegal or missing hexadecimal sequence in chunked-encoding
Probably due to emission of Early Hint lines

System configuration

Rails version:
5.2.0.rc2

Ruby version:
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16]

CURL output

Response Streaming Disabled

$ curl http://localhost:3000/ -v
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 3000 failed: Connection refused
*   Trying fe80::1...
* TCP_NODELAY set
* Connection failed
* connect to fe80::1 port 3000 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.59.0
> Accept: */*
>
< HTTP/1.1 103 Early Hints
< Link: </assets/application.self-f0d704deea029cf000697e2c0181ec173a1b474645466ed843eb5ee7bb215794.css?body=1>; rel=preload; as=style
< HTTP/1.1 103 Early Hints
< Link: </assets/action_cable.self-69fddfcddf4fdef9828648f9330d6ce108b93b82b0b8d3affffc59a114853451.js?body=1>; rel=preload; as=script
< HTTP/1.1 103 Early Hints
< Link: </assets/cable.self-8484513823f404ed0c0f039f75243bfdede7af7919dda65f2e66391252443ce9.js?body=1>; rel=preload; as=script
< HTTP/1.1 103 Early Hints
< Link: </assets/application.self-4616c39688369d8fb73b999da17bc349fb78f4eed1e6fd46e6d3d06693036ec5.js?body=1>; rel=preload; as=script
< HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Download-Options: noopen
< X-Permitted-Cross-Domain-Policies: none
< Referrer-Policy: strict-origin-when-cross-origin
< Content-Type: text/html; charset=utf-8
< ETag: W/"08fa8c699e026129ce9b647186e02a66"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _rails_issue_h2_early_hint_response_streaming_session=eVoybG9mcTBZREZ5TnJLWHhjb204Y3NZVkJ1aFdvSDJ1Y3JWMUNMSzhWMzBQakdESnJBQzdBT1pkWmdzTm1GS2o3MXY5WjVMY2VzcDh1RDk0c1Z3SzZxK2gxcW1CZGpXVzh1cnhUNXBmdElqb3FDUzRxZWVIdjdtdmErclRJeFZiRnNvV2U1aUFNaUpGb2UyQkc2cjVRPT0tLWRqdVIyaEl1Rmo5OHJ1RXczUFNaQUE9PQ%3D%3D--d002b0a00d1a1f9b9f1ac6121f4e502cdc27ad3e; path=/; HttpOnly
< X-Request-Id: 28914b93-28cc-4f71-a732-44f0ba092e70
< X-Runtime: 0.074322
< Transfer-Encoding: chunked
<
<!DOCTYPE html>
<html>
  <head>
    <title>RailsIssueH2EarlyHintResponseStreaming</title>
    <meta name="csrf-param" content="authenticity_token" />
<meta name="csrf-token" content="K8Tzil7JnimaTw+dJ3/EOBiC2kTbAAWD7u8VaXrExuoc1iIBw5yoxw9Lqlsy+OEsH6IX1x4d9WkIvh2PQHmL3w==" />

    <link rel="stylesheet" media="all" href="/assets/application.self-f0d704deea029cf000697e2c0181ec173a1b474645466ed843eb5ee7bb215794.css?body=1" data-turbolinks-track="reload" />
    <script src="/assets/action_cable.self-69fddfcddf4fdef9828648f9330d6ce108b93b82b0b8d3affffc59a114853451.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/cable.self-8484513823f404ed0c0f039f75243bfdede7af7919dda65f2e66391252443ce9.js?body=1" data-turbolinks-track="reload"></script>
<script src="/assets/application.self-4616c39688369d8fb73b999da17bc349fb78f4eed1e6fd46e6d3d06693036ec5.js?body=1" data-turbolinks-track="reload"></script>
  </head>

  <body>
    <h1>Hi</h1>

  </body>
</html>
* Connection #0 to host localhost left intact

Response Streaming Enabled

$ curl http://localhost:3000/ -v
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 3000 failed: Connection refused
*   Trying fe80::1...
* TCP_NODELAY set
* Connection failed
* connect to fe80::1 port 3000 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.59.0
> Accept: */*
>
< HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Download-Options: noopen
< X-Permitted-Cross-Domain-Policies: none
< Referrer-Policy: strict-origin-when-cross-origin
< Cache-Control: no-cache
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
< X-Request-Id: b6164427-2b5c-4f80-9829-0cebf7123e81
< X-Runtime: 0.091884
<
<!DOCTYPE html>
<html>
  <head>
    <title>RailsIssueH2EarlyHintResponseStreaming</title>
    <meta name="csrf-param" content="authenticity_token" />
<meta name="csrf-token" content="fVAAa8Tfg/MpE4n3WqIeG+lVfx9AIQofn4NFxHRRocQ01l8atAWuE78ZFGEcGH2RZcClnUx+OQFoHEt03Z5S4Q==" />

* Illegal or missing hexadecimal sequence in chunked-encoding
* Closing connection 0
curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding
    %                                                                                                                                                                                                                               FAIL: 56

@PikachuEXE
Copy link
Contributor Author

Might be related PRs:

@PikachuEXE
Copy link
Contributor Author

Anyone?

eileencodes added a commit to eileencodes/puma that referenced this issue Mar 28, 2018
Oops this was using `v` instead of `vs` here which means it couldn't
have been working.

Ref rails/rails#32329
and https://github.com/puma/puma/pull/1403/files#r176663645
nateberkopec pushed a commit to puma/puma that referenced this issue Mar 29, 2018
Oops this was using `v` instead of `vs` here which means it couldn't
have been working.

Ref rails/rails#32329
and https://github.com/puma/puma/pull/1403/files#r176663645
@PikachuEXE
Copy link
Contributor Author

Ping...

@PikachuEXE
Copy link
Contributor Author

Pong...

@rafaelfranca
Copy link
Member

Did you check if the linked PR fixed the issue?

@PikachuEXE
Copy link
Contributor Author

If you are talking about
puma/puma#1550
This is just a typo fix in puma which is unrelated

If you are talking about

@rails-bot rails-bot bot added the stale label Jul 31, 2018
@rails-bot
Copy link

rails-bot bot commented Jul 31, 2018

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 5-2-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@PikachuEXE
Copy link
Contributor Author

I think this is still a valid bug

@rails-bot rails-bot bot removed the stale label Aug 1, 2018
@matthewd
Copy link
Member

matthewd commented Aug 1, 2018

I agree this is a bug, but I think it's in the Puma side. (cc @eileencodes @schneems)

While we could remember that the response has started so there's no benefit to trying to send early hints, I think it's on Puma to actively ignore any hints it gets, because it owns the output stream that they're messing up.

I'm sure they'd love a pull request to fix it, if you're interested. (Specifically, I think the contents of the env[EARLY_HINTS] lambda needs to be wrapped in an e.g. if early_hints_okay, which starts true, and gets flipped to false when call returns or the response is hijacked... or something like that.)

@rails-bot
Copy link

rails-bot bot commented Oct 30, 2018

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 5-2-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot added the stale label Oct 30, 2018
@rails-bot rails-bot bot closed this as completed Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants