Skip to content

Proof of concept for detecting stream double consumption#1528

Closed
adriangb wants to merge 6 commits intoKludex:masterfrom
adriangb:stream-consumed
Closed

Proof of concept for detecting stream double consumption#1528
adriangb wants to merge 6 commits intoKludex:masterfrom
adriangb:stream-consumed

Conversation

@adriangb
Copy link
Contributor

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
Contributor 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.

1 participant