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

Incorrect assumption in werkzeug.serving about socket behavior #920

Closed
d42 opened this issue May 1, 2016 · 6 comments
Closed

Incorrect assumption in werkzeug.serving about socket behavior #920

d42 opened this issue May 1, 2016 · 6 comments

Comments

@d42
Copy link

d42 commented May 1, 2016

As we all know socket.send() doesn't guarantee all of the data getting sent

and this line:

self.wfile.write(data)

combined with gevent and the greatest webscale technology, known as docker has led me to just that behavior with responses getting truncated :3

It seems like the socket.SocketIO should care about it, but it doesn't

@untitaker
Copy link
Contributor

While you're probably correct (haven't done any research), please note that Werkzeug's server is only intended for development. Running it in Docker and with gevent leads me to believe that you don't use it for that purpose.

@d42
Copy link
Author

d42 commented May 1, 2016

I've been actually using docker for development and part of the code used gevent monkeypatches quite frivulously.
I probably wouldn't even notice it if it wouldn't break dontpanic :3

@odony
Copy link

odony commented Oct 25, 2017

I've experienced this bug in Python 3.5, but only when setting the underlying socket to non-blocking mode (e.g with settimeout). It turns out this is in fact caused by an upstream bug in Python 3: issue24291. The issue is fixed in Python 3.6 (see issue26721)

A workaround that has been implemented in other web servers is to wrap the wfile in an io.BufferedWriter (e.g in CPython's wsgiref in 3.5) or to change the wbufsize to enable buffering by default (e.g. see this gevent issue)

Not sure if werkzeug wants to implements a workaround too, or considers it a non-werkzeug issue.

@RonnyPfannschmidt
Copy link
Contributor

based on the provided information i believe this indeed is either a gevent bug or a stdlib bug, werkzeug uses write + flush on a supposed buffered file, which in turn should always work, now i wonder if this also happens on plain python, or only on gevent

@odony
Copy link

odony commented Oct 26, 2017

@RonnyPfannschmidt yes, I get it without gevent too, I just need to use a non-blocking socket in combination with werkzeug's WSGIRequestHandler. Gevent was just another example of the many projects who are indirectly affected by the upstream bug in Python 3.5 :-)

@davidism
Copy link
Member

davidism commented Dec 9, 2018

Given the circumstances this happens in, as well as the fact that it's fixed in Python 3.5 (3.4 goes EOL in March), I'm closing this.

@davidism davidism closed this as completed Dec 9, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants