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
Early hints + javascript_include_tag = Puma:ConnectionError #1640
Comments
I'm also seeing this error - any ideas to fix would be greatly appreciated! |
This error happens when the connection is lost before we're able to send any early hints. We could have the same situation even without early hints if the connection is lost before any response headers are sent, however Puma swallows these errors which I think is fine. A simple way to reproduce this is running this against your web server: require 'socket'
request = [
"GET /buildings HTTP/1.1",
"Host: 127.0.0.1:3000",
"\r\n"
]
socket = TCPSocket.new '127.0.0.1', 3000
socket.puts request.join("\r\n")
# Close socket without reading anything back from the server...
socket.close No error will appear in the client but the reported error will appear in the app logs. |
I've been thinking on how Puma should behave when the early hints can't be sent because the connection has been lost. I first thought that it should behave the same way it does when the connection is lost before main response is sent, I've seen that it swallows those errors (https://git.io/fjVL8) so perhaps we should do the same here. There's one consideration though. Because the early hints are sent at the very beginning of the app execution, we may want to abort this request altogether and save resources by throwing an exception and causing Rails to interrupt execution. Finally I decided to overlook that case just because I believe it's least surprising from the Rack app point of view. Also I haven't seen any other example of the web server interrupting the apps execution due to an error on the lower layer. Fixes puma#1640.
I've been thinking on how Puma should behave when the early hints can't be sent because the connection has been lost. I first thought that it should behave the same way it does when the connection is lost before main response is sent, I've seen that it swallows those errors (https://git.io/fjVtg) so perhaps we should do the same here. There's one consideration though. Because the early hints are sent at the very beginning of the app execution, we may want to abort this request altogether and save resources by throwing an exception and causing Rails to interrupt execution. Finally I decided to overlook that case just because I believe it's least surprising from the Rack app point of view. Also I haven't seen any other example of the web server interrupting the apps execution due to an error on the lower layer. Fixes puma#1640.
* Swallow connection errors when sending early hints I've been thinking on how Puma should behave when the early hints can't be sent because the connection has been lost. I first thought that it should behave the same way it does when the connection is lost before main response is sent, I've seen that it swallows those errors (https://git.io/fjVtg) so perhaps we should do the same here. There's one consideration though. Because the early hints are sent at the very beginning of the app execution, we may want to abort this request altogether and save resources by throwing an exception and causing Rails to interrupt execution. Finally I decided to overlook that case just because I believe it's least surprising from the Rack app point of view. Also I haven't seen any other example of the web server interrupting the apps execution due to an error on the lower layer. Fixes #1640. * Adds a test * Updates test as per @nateberkopec's suggestion
Steps to reproduce
Procfile enables early hints eg. web: bundle exec puma -C config/puma.rb --early-hints
Make use of
javascript_include_tag
helperProduction environment on Heroku
Expected behavior
Testing out --early-hints on Heroku, I would expect the hints to be generated as described in Implement H2 Early Hints for Rails.
Actual behavior
I'm seeing some intermittent socket timeout errors when I have --early-hints enabled on my app, which is hosted on Heroku. It's only showing up about once a day, and only in production.
Some lucky visitor's request is throwing one Puma:ConnectionError for each
javascript_include_tag
in my application layout. If one call fails, they all fail in the order they appear in the template. I've never experienced the end-result personally, leading me to guess that the visitor probably won't notice as their script tags would just load normally.System configuration
Ruby version: 2.4.1
Rails version: 5.2.0
Puma version: 3.11.4
The text was updated successfully, but these errors were encountered: