Skip to content

Win32 FileStream turns async reads into sync reads #16341

@stephentoub

Description

@stephentoub

When filling the internal buffer, Win32FileStream does this as part of ReadAsync:

Task<int> readTask = ReadInternalCoreAsync(_buffer, 0, _bufferSize, 0, cancellationToken);
_readLen = readTask.GetAwaiter().GetResult();

Ugh!

There's a large comment about how this is done to avoid concurrent use of the buffer when concurrent read operations are issued, but we should be able to work around that using something similar to what I previously did for WriteAsync and FlushAsync, with the HasActiveBufferOperation mechanism (dotnet/corefx#2929).

As it currently stands, it appears that when async reads are performed against a Win32FileStream and those reads are smaller than the file stream's buffer, all such reads will be made synchronous, either because they're pulling from the buffer or because they're blocking waiting for the buffer to be filled.

cc: @ericstj, @ianhays, @JeremyKuhne

Metadata

Metadata

Assignees

Labels

area-System.IOenhancementProduct code improvement that does NOT require public API changes/additionsos-windowstenet-performancePerformance related issuewishlistIssue we would like to prioritize, but we can't commit we will get to it yet

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions