-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
StreamWriter might not call Flush #89480
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsDescriptionWhile working on #88244 I found that there might be a possible bug in
This would however be a breaking change and therefor I am not sure, if this can be considered. However if this is going to be changed, then Reproduction StepsIt is hard to create a repro, since this can be the case if the underlying stream is slow and we are writing a lot of data to it. So this repro makes some assumptions var sr = new StreamReader(new MemoryStream()); Expected behaviorException to be thrown if the WriteTask is still ongoing or if Flushing failed. Actual behaviorSilently closes the stream without any issues being reported Regression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
Quoting from #88244 (comment):
|
Description
While working on #88244 I found that there might be a possible bug in
StreamWriter
s implementation when disposing.Dispose(bool disposing)
andDisposeAyncCore
both callCheckAsyncTaskInProgress()
which might throw. In these cases Flush(Async) is not called, which is fine, however, because this is all wrapped in a try-finally-block, both callClose()
on the underlying Stream and set_disposing
to true, which then does not allow for a retry onDispose
norFlush
since the Writer is "disposed" at this point. I think this is a bug and ifCheckAsyncTaskInProgress()
throws it shouldn't be caught but it should throw. Same for Flush, as a user I should know when Flush throws and it shouldn't silently close the stream.This would however be a breaking change and therefor I am not sure, if this can be considered. However if this is going to be changed, then
StreamReader
should be fixed to, since I just mirrored the implementation ofStreamWriter
ontoStreamReader
in #88244Reproduction Steps
It is hard to create a repro, since this can be the case if the underlying stream is slow and we are writing a lot of data to it. So this repro makes some assumptions
var sr = new StreamReader(new MemoryStream());
//do not await the write
sr.WriteAsync("abc");
//dispose right away
sr.Dispose();
// assume flush failed
sr.Flush();
Expected behavior
Exception to be thrown if the WriteTask is still ongoing or if Flushing failed.
Actual behavior
Silently closes the stream without any issues being reported
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: