Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Missed case for tracking async flush operations
  • Loading branch information
tymlipari committed Aug 19, 2015
commit cfeefdbb26fe7073cf82bfb0e7b72cbe6bbb44d6
10 changes: 10 additions & 0 deletions src/System.IO.FileSystem/src/System/IO/Win32FileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,16 @@ private void FlushWrite(bool calledFromFinalizer)
{
writeTask.GetAwaiter().GetResult();
}

// If not completing synchronously, ensure the async flush operation
// is tracked in case of incoming WriteAsync calls.
else
{
if (ActiveBufferOperation())
_activeBufferOperation = Task.WhenAll(_activeBufferOperation, writeTask);
else
_activeBufferOperation = writeTask;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time we call FlushWriteAsync, we do these four lines to update _activeBufferOperation. Should they just be moved into FlushWriteAsync? This is the only place where there's the potential for avoiding it, and it's an uncommon case (an async FileStream being finalized with data in the buffer) and a cheap enough operation that the overhead doesn't seem problematic even if it's unnecessary. Worst case, it could be moved into its own helper rather than repeating it each time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just personal preference, so feel free to leave it as-is, but I prefer to write such things as:

_activeBufferOperation = ActiveBufferOperation() ?
    Task.WhenAll(writeTask, _activeBufferOperation) :
    writeTask;

That way it's clear that we're always assigning into the field, and the conditional just determines exactly what we're assigning.

}
}
else
{
Expand Down