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

Zope 5.8.1 breaks using wsgiref #1171

Closed
icemac opened this issue Oct 10, 2023 · 9 comments · Fixed by #1172 or #1175
Closed

Zope 5.8.1 breaks using wsgiref #1171

icemac opened this issue Oct 10, 2023 · 9 comments · Fixed by #1172 or #1175
Labels

Comments

@icemac
Copy link
Member

icemac commented Oct 10, 2023

What I did:

I am using Python's stdlib wsgiref in selenium tests to start a simple WSGI server.

What I expect to happen:

Using wsgiref should be possible.

What actually happened:

wsgiref uses a socket as stdin for the WSGI environment.
And Zope 5.8.1+ uses read() to get the data from this socket, the execution is blocked and later on runs into a timeout.

Previous versions (via cgi module) called readline() on the socket which does not block.

(Sorry I cannot provide a minimal test example as it involves too much custom code. Additionally I did not find an easy way to start a Zope instance using wsgiref – the examples for using a different WSGI server in the docs seem to require some preparation.)

What version of Python and Zope/Addons I am using:

  • Zope 5.8.6
  • MacOS 13.6
  • Python 3.11
@icemac icemac added the bug label Oct 10, 2023
@icemac
Copy link
Member Author

icemac commented Oct 10, 2023

@d-maurer Could you please have a look at this issue, it seems to be there since #1094.

@d-maurer
Copy link
Contributor

d-maurer commented Oct 11, 2023 via email

@icemac
Copy link
Member Author

icemac commented Oct 11, 2023

@d-maurer Thank you for your analysis, I'll try to gather more information.

@d-maurer
Copy link
Contributor

d-maurer commented Oct 11, 2023 via email

@d-maurer
Copy link
Contributor

d-maurer commented Oct 11, 2023 via email

@d-maurer
Copy link
Contributor

d-maurer commented Oct 12, 2023 via email

@d-maurer
Copy link
Contributor

Their may still be a problem with WSGI servers passing the socket to the application: Zope now ensures that it does not read beyond Content-Length but it does not ensure that the request body is read (unless we have an application/x-www-form-urlencoded or multipart/form-data POST request). Should the application not read the body completely, then remaining body content could be misinterpreted as belonging to a follow up request on the same connection.

@d-maurer d-maurer mentioned this issue Oct 14, 2023
@d-maurer
Copy link
Contributor

#1172 has introduced a workaround but I fear it is not the optimal solution:
"https://peps.python.org/pep-3333/#input-and-error-streams" recommends that the web server signals EOF when the application tries to read beyond Content-Length.
Apparently, some WSGI servers (among them wsgiref) do not honor the recommendation. Zope does not (and should not) know whether it is integrated with such a WSGI server. #1172 uses a crude guess and applies a wrapper when the guess indicates "maybe".

A better solution would be the implementation of the wrapping in a WSGI middleware. Integrators combining Zope with a WSGI server not honoring the recommendation would put this middleware component in between, integrators using a well behaving WSGI server do not.
Such a middleware component would not be restricted to Zope but other web application frameworks could profit as well.

d-maurer added a commit that referenced this issue Oct 17, 2023
d-maurer added a commit that referenced this issue Oct 18, 2023
* Revert "honor a request's `Content-Length` (#1172)"

This reverts commit d87e918.

* New `paste.filter_app_factory` entry point `content_length` to allow administrators to fix #1171

* wording in `CHANGES.rst

* apply review suggestion: rename `test_paste` to `test_pastefilter`
@d-maurer
Copy link
Contributor

We decided that Zope should not apply a workaround for this problem by default.
Instead #1175 provides a PasteDeploy filter (aka "WSGI middleware component") which an administrator can include in the WSGI pipeline should the used WSGI server make a workaround necessary.

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

Successfully merging a pull request may close this issue.

2 participants