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

Timeouts after 10 mins with error code 1006 #7

Closed
imrankhan17 opened this issue Jun 17, 2021 · 9 comments
Closed

Timeouts after 10 mins with error code 1006 #7

imrankhan17 opened this issue Jun 17, 2021 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@imrankhan17
Copy link

I have a flask-sock app deployed using gunicorn and nginx. I get disconnected after 10 minutes (sometimes sooner) with the following error: Disconnected (code: 1006, reason: "")

Is there a way to configure the timeout length?

I'm running it with: gunicorn --bind 127.0.0.1:5655 --workers 4 --threads 20 wsgi:app

@miguelgrinberg
Copy link
Owner

miguelgrinberg commented Jun 17, 2021

This could be the browser closing the socket due to inactivity. The WebSocket protocol has a ping/ping mechanism, but most browsers do not implement it. The server implements the pong message right now, but it does not send pings to clients (though I've been considering adding this).

What most people do is just send a dummy message every 50 seconds or so to keep them from timing out (I believe some browsers timeout sockets at one minute).

@miguelgrinberg miguelgrinberg added the question Further information is requested label Jun 17, 2021
@imrankhan17
Copy link
Author

Thanks for the suggestion. As it happens I managed to fix the issue with this: https://stackoverflow.com/questions/19304157/getting-the-reason-why-websockets-closed-with-close-code-1006/57706152#57706152

@miguelgrinberg
Copy link
Owner

@imrankhan17 I'm not sure that's the best solution, because making the nginx timeouts longer will (I think) affect your non-websocket routes as well. As I said above, the best to beat timeouts is to have a little interval function in the browser that sends a dummy package regularly.

@imrankhan17
Copy link
Author

I have a separate nginx config for this websocket route so that shouldn't be an issue. With your suggestion, do you mean it's the client's responsibility to send dummy messages or can I do the same from the server too?

@miguelgrinberg
Copy link
Owner

miguelgrinberg commented Jun 17, 2021

It does not matter who sends the packet, the only purpose is to keep some traffic in the line to prevent the timeouts. I suggested you do it from the client because it is easier. I was considering adding pings in the server as a definitive solution to this problem.

@imrankhan17
Copy link
Author

Ok great, I'll look into adding in the pings but it'd be great if you added it into the package too.

@miguelgrinberg miguelgrinberg self-assigned this Jun 17, 2021
@miguelgrinberg miguelgrinberg added enhancement New feature or request and removed question Further information is requested labels Jun 17, 2021
@miguelgrinberg
Copy link
Owner

Yes, keeping this issue open so that I don't forget!

@sanhardik
Copy link

@miguelgrinberg Is this something that you are working on ?
Would this be a change in simple-websockets code base ?

I was thinking adding an option in initialization for enabling the ping and then checking on time in this code to send a ping.

@miguelgrinberg
Copy link
Owner

@sanhardik I haven't had time to look at this yet, but yes, doing this in the thread may be the best solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants