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
socket hang up and keep-alive connections #4764
Comments
Thank you for the detailed bug report! In HTTP/1.1, Keep-Alive support is implicit unless As you can see, there is no
I don't think that this is a bug in Cypress - Cypress receives the headers instructing it to redirect and immediately responds on the same socket, which is correct behavior. The bug is in Django for not actually keeping the socket alive. Regardless, retrying one time on an ECONNRESET from a socket that should've been kept-alive is a good idea I think, I doubt that Django is the only web server that has made or will make this mistake. Also, major browsers appear to do this, and Cypress is supposed to behave like a normal browser. In the meantime, switching to the latest Django should fix this issue. If switching is too much right now, you could try sending |
Good point about browsers doing this. I can confirm this about Chrome: To be more precise it seems to open 2 connections simultaneously. Then, when the first one closes it retries the request in the second one. And yes, Django seems to have had a bug, that was fixed in 2.1.4. I've just confirmed it. With Django 2.1.4 I can see multiple requests over the course of one connection: The workaround for older versions is to add the following middleware:
import wsgiref.util
from django.conf import settings
from django.core.exceptions import MiddlewareNotUsed
# or else it triggers AssertionError: Hop-by-hop headers not allowed
# https://stackoverflow.com/a/57113570/52499
wsgiref.util._hoppish = {
'keep-alive':1, 'proxy-authenticate':1,
'proxy-authorization':1, 'te':1, 'trailers':1, 'transfer-encoding':1,
'upgrade':1
}.__contains__
class NoKeepAliveMiddleware:
def __init__(self, get_response):
if not settings.DEBUG:
raise MiddlewareNotUsed()
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
response['Connection'] = 'close'
return response
...
MIDDLEWARE = [
...
'myapp.middleware.NoKeepAliveMiddleware',
...
]
... Do note, that generally, you want to put it before Also, there's probably not a bug, but behavior that could be improved. Ideally in P.S. To be honest I tried to reproduce the behavior with a freshly created Django 2.0.2 project, and failed. The trick is to add |
@x-yuri we handle all of the low level socket layer retrying manually ourselves (as does browsers). There's no way to generically implement it in the We are able to make them when we are context aware (such as a |
Cypress will retry on an ECONNRESET: #4015 I believe that was the only action item here, so closing for now. |
Current behavior:
Requests that result in a redirect fail with "socket hang up" error.
Desired behavior:
They succeed.
Steps to reproduce: (app code and test code)
cypress/integration/1.spec.js
:Versions
Cypress 3.4.0, Django 2.0.2
More info
This is supposedly caused by a bug in Django development web server, which was fixed in
2.1.4
. Before this fix Django unconditionally closed the connection after the first request.The thing is at
3.3.0
Cypress switched tokeep-alive
connections, so now it tries to do a second request (to the URL it was given to in the first one) over the same connection. But at about the same time Django closes the connection, which results in the error in the title.I'm going to confirm in the near future if switching to the latest Django handles the issue.
Then, there's an open issue in Python's
requests
library (which is not used here, but still), that claims that a client that doesn't establish a new connection in this case is not well-behaved. And there are open issues inrequest
package which Cypress uses. So the bug seems to be on the client side as well. Or rather on the client side. I'm not sure.The text was updated successfully, but these errors were encountered: