Skip to content

Conversation

@anuraaga
Copy link
Collaborator

For .read() methods

https://docs.python.org/3/library/io.html#io.RawIOBase.read

Fewer than size bytes may be returned if the operating system call returns fewer than size bytes.

In practice, all WSGI servers seem to buffer the request to content-length before calling the app...except for pyvoy ;) Incidentally that means pyvoy is able to pass bidi streaming tests with WSGI too. I'm currently debugging an occasional macOS crash which seems envoy-related, but am feeling pretty good about the project.

I also took care to follow the WSGI spec "The application should not attempt to read more data than is specified by the CONTENT_LENGTH variable.". If this text wasn't there, it would be easiest to just call .read() with no parameter.

https://peps.python.org/pep-3333/#input-and-error-streams

I'm interested in adding pyvoy to conformance tests after some more debugging, but without it it's quite challenging to add a regression test for this change. I wanted to separate out the logic change from any testing changes but let me know if I should hold off until having that regression test.

environ: WSGIEnvironment, content_length: int
) -> bytes:
bytes_read = 0
chunks = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we pre-allocate a bytearray to be size content_length and then use readinto?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WSGI doesn't actually define readinto.

https://peps.python.org/pep-3333/#input-and-error-streams

Since most servers will prebuffer anyways, I added a small optimization for that case instead

@anuraaga anuraaga force-pushed the read-content-length branch from ea29372 to f5f1139 Compare October 22, 2025 01:15
@anuraaga anuraaga merged commit 0d4824e into connectrpc:main Oct 22, 2025
27 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants