Conversation
… StreamReader as it is implemented for StreamWriter. Changed StreamWriter to call base.Dispose(disposing) and set _disposed to true, even if stream is not closable
|
Tagging subscribers to this area: @dotnet/area-system-io Issue Details
fixes #88244 I still think there are some bugs in StreamWriter and I think it makes sense to add
|
|
I might need some help to understand where the issue from the Analysis is coming from. Did I miss something? |
src/libraries/System.Private.CoreLib/src/System/IO/StreamReader.cs
Outdated
Show resolved
Hide resolved
|
The validation errors are unrelated. |
jozkee
left a comment
There was a problem hiding this comment.
Can you please also add tests for StreamReader? You can get inspiration from https://github.com/dotnet/runtime/blob/main/src/libraries/System.IO/tests/StreamWriter/StreamWriter.DisposeAsync.cs
src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/StreamReader.cs
Outdated
Show resolved
Hide resolved
|
CI issues are related, you need to add the API changes to the ref assembly. |
src/libraries/System.Private.CoreLib/src/System/IO/StreamReader.cs
Outdated
Show resolved
Hide resolved
There's no reason to add |
I wrote a test already, but I couldnt figure out how to update the ref assemblies and so I couldn't run the test, but now I know how to do it |
Added StreamWriter.CloseStreamFromDisposeAsync Added same for StreamReader Added missing Refs Added Tests
src/libraries/System.Private.CoreLib/src/System/IO/StreamReader.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/StreamReader.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/StreamReader.cs
Outdated
Show resolved
Hide resolved
…neccessary call to ThrowIfDisposed
|
all comments are addressed i think. should I resolve the conversations or is who started the conversions going to resolve it? I usually wait for the person that started it to resolve it, so I know they are OK with the change. |
|
It's up to you but typically folks resolve comments when they push the change that addresses them. |
| Assert.Null(await input.ReadLineAsync(default)); | ||
| Assert.Equal("", await input.ReadToEndAsync()); | ||
| Assert.Equal("", await input.ReadToEndAsync(default)); | ||
| await input.DisposeAsync(); |
There was a problem hiding this comment.
Can you please add this line to the existing test above and remove this one test to avoid duplication?
There was a problem hiding this comment.
I think these to methods are testing different behavior, since Dispose is calling "Close()" on the underlying stream and DisposeAsync() is calling "DisposeAsync()" on the underlying stream. But if this isn't a concern I will happily change this.
There was a problem hiding this comment.
I still think you should apply my suggestion here because TestNullTextReaderAsync above is already testing Async conterparts.
| Assert.Equal(token, ex.CancellationToken); | ||
| ex = await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await input.ReadToEndAsync(token)); | ||
| Assert.Equal(token, ex.CancellationToken); | ||
| await input.DisposeAsync(); |
| { | ||
| _disposed = true; | ||
| _charLen = 0; | ||
| await base.DisposeAsync().ConfigureAwait(false); |
There was a problem hiding this comment.
I stared at this for a long time and seems to me that this is the right thing to do, as per the docs:
An object must also call the DisposeAsync method of its base class if the base class implements IAsyncDisposable.
I don't know why we weren't doing this before. @stephentoub thoughts?
There was a problem hiding this comment.
@jozkee, @stephentoub what do you think we should do here?
There was a problem hiding this comment.
What you have here looks good to me.
|
@dersia ping, I don't see your commits addressing the feedback. Bear in mind the code cut for .NET 8 RC1 is next week. |
|
I've reviewed this PR to assess whether or not we'd want to merge it in for .NET 8, and my conclusion is that we should hold off on this until .NET 9 Preview 1. If there is a compelling value proposition for this to make it into .NET 8 though, I'm happy to take more data points into consideration. My considerations thus far are:
With the potential for the diagnostics to be introduced, getting this into .NET 9 Preview 1 will still require we scope out upstack derivatives and assess if this will disrupt code flow. If this does introduce the need to make compensating changes in other repos, then we would consider handling this as a source-incompatible breaking change. We need to assess the upstack code flow impact before merging; if compensating changes are required, then we'll want to hold off on merge until .NET 8 is locked down for GA so that we don't disrupt code flow or introduce merge conflicts. @dersia Thank you for this contribution and the efforts you've put into it. With the plan of waiting for .NET 9 Preview 1, we would be letting this PR remain open for several weeks before merging it in. |
|
This pull request has been automatically marked |
|
This pull request will now be closed since it had been marked |
fixes #88244 #88246
I still think there are some bugs in StreamWriter and I think it makes sense to add
CloseAsync()to Stream, since as of now, it is still always callingDispose(true)which is sync, but I will open another issue for that.