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

Never decalre reader with use on ctx.Request.Body #564

Closed
xperiandri opened this issue Oct 26, 2023 · 4 comments · Fixed by #615
Closed

Never decalre reader with use on ctx.Request.Body #564

xperiandri opened this issue Oct 26, 2023 · 4 comments · Fixed by #615
Assignees
Labels
bug Reproducible bug

Comments

@xperiandri
Copy link

this

use reader = new StreamReader(ctx.Request.Body, Encoding.UTF8)

disposes body, because the reader disposes underlying stream.
Which must not be done in any case!

@64J0
Copy link
Member

64J0 commented Oct 26, 2023

I did not get it, what is the problem with disposing the request body after reading it?

@xperiandri
Copy link
Author

The problem is that Giraffe is not an owner of it. The owner of it is an appropriate ASP.NET core middleware.
Giraffe must not dispose the stuff it is not owner of.
It leads to unexpected behavior for the consumer.

@64J0
Copy link
Member

64J0 commented Oct 29, 2023

I see, thanks for the explanation. I agree then!

@Banashek
Copy link
Contributor

Looks like the leaveOpen parameter could be specified to allow disposal of the StreamReader without disposing the underlying resource: doc reference

use reader = new StreamReader(ctx.Request.Body, Encoding.UTF8, leaveOpen = true)

@64J0 64J0 added the bug Reproducible bug label Sep 6, 2024
@64J0 64J0 closed this as completed in #615 Sep 20, 2024
@64J0 64J0 self-assigned this Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reproducible bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants