Skip to content

Commit 3cbed4b

Browse files
authored
add missing GC.SuppressFinalize(this) to FileStream.DisposeAsync (#65899)
* add missing GC.SuppressFinalize(this) to FileStream.DisposeAsync * DerivedFileStreamStrategy.DisposeAsync does not need to call _fileStream.BaseDisposeAsync, as FileStream.DisposeAsync calls Dispose(false) now
1 parent 097d9ea commit 3cbed4b

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/libraries/System.IO.FileSystem/tests/FileStream/DisposeAsync.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public async Task DisposeAsyncClosesHandle()
2020
}
2121

2222
[Fact]
23-
[ActiveIssue("https://github.com/dotnet/runtime/issues/65835")]
2423
public async Task DisposeAsyncFlushes()
2524
{
2625
string path = GetTestFilePath();

src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,12 @@ public override long Position
497497
// _strategy can be null only when ctor has thrown
498498
protected override void Dispose(bool disposing) => _strategy?.DisposeInternal(disposing);
499499

500-
public override ValueTask DisposeAsync() => _strategy.DisposeAsync();
500+
public async override ValueTask DisposeAsync()
501+
{
502+
await _strategy.DisposeAsync().ConfigureAwait(false);
503+
Dispose(false);
504+
GC.SuppressFinalize(this);
505+
}
501506

502507
public override void CopyTo(Stream destination, int bufferSize)
503508
{
@@ -576,8 +581,6 @@ internal Task BaseWriteAsync(byte[] buffer, int offset, int count, CancellationT
576581
internal ValueTask BaseWriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
577582
=> base.WriteAsync(buffer, cancellationToken);
578583

579-
internal ValueTask BaseDisposeAsync() => base.DisposeAsync();
580-
581584
internal Task BaseCopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
582585
=> base.CopyToAsync(destination, bufferSize, cancellationToken);
583586

src/libraries/System.Private.CoreLib/src/System/IO/Strategies/DerivedFileStreamStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public override Task FlushAsync(CancellationToken cancellationToken)
146146
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
147147
=> _fileStream.BaseCopyToAsync(destination, bufferSize, cancellationToken);
148148

149-
public override ValueTask DisposeAsync() => _fileStream.BaseDisposeAsync();
149+
public override ValueTask DisposeAsync() => _strategy.DisposeAsync();
150150

151151
protected sealed override void Dispose(bool disposing) => _strategy.DisposeInternal(disposing);
152152
}

0 commit comments

Comments
 (0)