Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when async operation fails with ERROR_OPERATION_ABORTED, we should ignore numBytes that can be != 0 #57229

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -195,34 +195,33 @@ private static void IOCallback(uint errorCode, uint numBytes, NativeOverlapped*

internal void Complete(uint errorCode, uint numBytes)
{
Debug.Assert(errorCode == Interop.Errors.ERROR_SUCCESS || numBytes == 0, $"Callback returned {errorCode} error and {numBytes} bytes");

OSFileStreamStrategy? strategy = _strategy;
ReleaseResources();

if (strategy is not null && _bufferSize != numBytes) // true only for incomplete operations
{
strategy.OnIncompleteOperation(_bufferSize, (int)numBytes);
}

switch (errorCode)
{
case Interop.Errors.ERROR_SUCCESS:
case Interop.Errors.ERROR_BROKEN_PIPE:
case Interop.Errors.ERROR_NO_DATA:
case Interop.Errors.ERROR_HANDLE_EOF: // logically success with 0 bytes read (read at end of file)
if (_bufferSize != numBytes) // true only for incomplete operations
{
strategy?.OnIncompleteOperation(_bufferSize, (int)numBytes);
}
// Success
_source.SetResult((int)numBytes);
break;

case Interop.Errors.ERROR_OPERATION_ABORTED:
strategy?.OnIncompleteOperation(_bufferSize, 0); // don't use numBytes here, as it can be != 0 for this errorCode (#57212)
// Cancellation
CancellationToken ct = _cancellationRegistration.Token;
_source.SetException(ct.IsCancellationRequested ? new OperationCanceledException(ct) : new OperationCanceledException());
break;

default:
// Failure
strategy?.OnIncompleteOperation(_bufferSize, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Do we care to add a comment here explaining why 0 for the default case?

_source.SetException(Win32Marshal.GetExceptionForWin32Error((int)errorCode));
break;
}
Expand Down