Minimal api stream sample #26437
Conversation
Rick-Anderson
left a comment
There was a problem hiding this comment.
Super minor changes
|
@sammychinedu2ky I did suggestions so you just have to "Add suggestion to batch" and then "Commit" |
Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
I've added the changes |
Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
|
ooh, I see the logger you added, cool. I have added the changes |
|
On the other PR, See https://github.com/dotnet/AspNetCore.Docs/blob/main/.gitignore#L15-L16 and check in the solution file. Usually you don't need the sln file so we ignore it. |
|
ooh ok let me work on that |
|
Please how did you get to see the sln file when it wasn't pushed? |
I didn't, I just figured you had one sln for both projects because that's typical. |
ooh I see 😅 |
|
So I should work on putting the test in a single project? |
Co-authored-by: David Fowler <davidfowl@gmail.com>
…mmychinedu2ky/AspNetCore.Docs into minimal-api-stream-sample-sam
Co-authored-by: David Fowler <davidfowl@gmail.com>
|
@sammychinedu2ky The code is almost complete, but we need to discuss the hardest part of this PR, the performance and potential security issues:
To avoid making the sample more complex than it needs to be, a happy medium would be to limit the size of the buffer we use for the memory stream. |
I can use a 429 if trywrite returns false or let me reduce it to 20 |
But won't I still need to return a 429 if it exceeds 20? |
|
We could do some back of the napkin math here and come up with some numbers that are reasonable and show readers how those calculations affect the limits. Lets say we're willing to use 500MB on this message processing (we're on a budget here). If the max message size is 1MB, we can support up to 500 concurrent requests. We can bound the channel to 500 and use Now limiting the request body to 1MB is interesting, as this will still land us in the LOH range. We also don't want to start with a 1MB buffer as that's wasteful for small buffers but we want to resize up to 1MB and then explode for buffers over that size. I'm still thinking about the most reasonable way to accomplish that without exploding people's heads. The other option is to stay below the LOH size (85K) and allow up to 80K bodies for this endpoint (which would leave a bounded channel around 6,400). |
ok but the body size for the sample is 63 bytes |
Co-authored-by: David Fowler <davidfowl@gmail.com>
But people copy and paste sample code into applications and will blame Microsoft when there's a security breach 😄. The sample payload if 63 bytes, but an attacker can send any size post (well up to ~28.6 MB by default). |
You're right 😅 |
…mmychinedu2ky/AspNetCore.Docs into minimal-api-stream-sample-sam
Co-authored-by: David Fowler <davidfowl@gmail.com>
Co-authored-by: David Fowler <davidfowl@gmail.com>
davidfowl
left a comment
There was a problem hiding this comment.
This looks clean @sammychinedu2ky. I hope you had fun with it!
Yh it was quite insightful 😎and fun as well |
Added sample code for an issue #26374
Fixes #26346