Skip to content

Commit

Permalink
add missing GC.SuppressFinalize(this) to FileStream.DisposeAsync (#65899
Browse files Browse the repository at this point in the history
)

* add missing GC.SuppressFinalize(this) to FileStream.DisposeAsync

* DerivedFileStreamStrategy.DisposeAsync does not need to call _fileStream.BaseDisposeAsync, as FileStream.DisposeAsync calls Dispose(false) now
  • Loading branch information
adamsitnik authored Mar 1, 2022
1 parent 097d9ea commit 3cbed4b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public async Task DisposeAsyncClosesHandle()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/65835")]
public async Task DisposeAsyncFlushes()
{
string path = GetTestFilePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,12 @@ public override long Position
// _strategy can be null only when ctor has thrown
protected override void Dispose(bool disposing) => _strategy?.DisposeInternal(disposing);

public override ValueTask DisposeAsync() => _strategy.DisposeAsync();
public async override ValueTask DisposeAsync()
{
await _strategy.DisposeAsync().ConfigureAwait(false);
Dispose(false);
GC.SuppressFinalize(this);
}

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

internal ValueTask BaseDisposeAsync() => base.DisposeAsync();

internal Task BaseCopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
=> base.CopyToAsync(destination, bufferSize, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public override Task FlushAsync(CancellationToken cancellationToken)
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
=> _fileStream.BaseCopyToAsync(destination, bufferSize, cancellationToken);

public override ValueTask DisposeAsync() => _fileStream.BaseDisposeAsync();
public override ValueTask DisposeAsync() => _strategy.DisposeAsync();

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

0 comments on commit 3cbed4b

Please sign in to comment.