-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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.DisposeAsync
disposes the underlying Stream
synchronously
#88246
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsDescriptionI discovered issue this while filing #88244. By default, See runtime/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs Lines 241 to 257 in 2a22adb
and runtime/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs Lines 211 to 234 in 2a22adb
Reproduction StepsExpected behaviorActual behaviorRegression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
I also think it should call |
I will take care of this as part of #88244 |
I think for compatiblity reasons we should continue calling |
yeah, |
Right. But fixing this issue would be a behavioral change too, so if it's OK to make that behavioral change, then why shouldn't it be OK to make this other small behavioral change too. |
@Neme12 because changing |
We have an example in Npgsql https://github.com/npgsql/Npgsql/blob/main/src/Npgsql/NpgsqlRawCopyStream.cs#L353-L376 of a stream that should ideally take advantage of async if it's there. NpgsqlRawCopyStream is the base stream used in our StreamReader/Writer derived types (same file, see NpgsqlCopyTextReader/Writer) It seems its made very hard to have StreamWriter call DisposeAsync on the underlying stream, many methods do GetType() == typeof(StreamWriter) checks and CloseStreamDuringDispose etc are all private, the * truly * async FlushAsync implementation is also private. I would welcome any fixes or workarounds to get StreamReader/Writer to respect DisposeAsync. |
Description
I discovered issue this while filing #88244 and looking at the source code. By default,
StreamWriter.Dispose
also disposes/closes the underlyingStream
.DisposeAsync
should close the underlyingStream
asynchronously, but currently closes it synchronously.See
runtime/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs
Lines 241 to 257 in 2a22adb
and
runtime/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs
Lines 211 to 234 in 2a22adb
Reproduction Steps
Expected behavior
Actual behavior
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: