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

Proof of concept for detecting stream double consumption #1528

Closed
wants to merge 6 commits into from

Conversation

adriangb
Copy link
Member

As per #1519 (comment) instead of "fixing" this issue we may want to want to write better documentation and warn/raise exceptions.

This is a proof of concept for how we might go about detecting problematic behaviors or raising errors.

I'm not sure that raising a runtime error here is exactly the only thing we want to do.
We could:

  1. Raise an error if the middleware tries to consume the request body.
  2. Warn if the middleware tries to consume the request body.
  3. Warn if the middleware consumed the request body and then the endpoint tries to do this again.
  4. Detect if the middleware consumed all of or only part of the body stream.
  5. Insert a new ASGI receive message with b"" so that the endpoint doesn't fail and instead interprets this as "nothing left in the body"

There are obviously many variations to this, but I think the mechanisms I'm proposing here could apply to all of them.

@adriangb adriangb closed this May 6, 2022
@adriangb
Copy link
Member Author

adriangb commented May 6, 2022

An alternative to all of this might be to wrap the stream with something that always returns b"" instead of hanging

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.

None yet

1 participant