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

Conversation

adamsitnik
Copy link
Member

In #57212, I've validated that when async WriteFile operation fails with ERROR_OPERATION_ABORTED, the reported number of transferred bytes can be different than zero. Moreover, its value can be bigger than the number of bytes that we have requested to transfer when the operation was started, so we can assume that this value is always invalid in such case and just use zero instead.

Process terminated. Assertion failed.
Callback returned 995 error and 1547079704 bytes
   at Microsoft.Win32.SafeHandles.SafeFileHandle.OverlappedValueTaskSource.Complete(UInt32 errorCode, UInt32 numBytes) in /_/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs:line 198
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pNativeOverlapped) in /_/src/coreclr/System.Private.CoreLib/src/System/Threading
System.IO.Tests.FileStream_WriteAsync_AsyncWrites.TriggerTheProblemAsync [FAIL]
  System.Exception : The error code was 995 and numBytes was 189216864
  Stack Trace:
    /_/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs(101,0): at Microsoft.Win32.SafeHandles.SafeFileHandle.OverlappedValueTaskSource.GetResult(Int16 token)
    /_/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs(96,0): at Microsoft.Win32.SafeHandles.SafeFileHandle.OverlappedValueTaskSource.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
    /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs(251,0): at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
    --- End of stack trace from previous location ---
    /_/src/libraries/System.IO.FileSystem/tests/FileStream/WriteAsync.cs(131,0): at System.IO.Tests.FileStream_AsyncWrites.WriteAsyncCancelledFile(Int32 bufferSize, FileOptions fileOptions)
    /_/src/libraries/System.IO.FileSystem/tests/FileStream/WriteAsync.cs(110,0): at System.IO.Tests.FileStream_AsyncWrites.TriggerTheProblemAsync()
    --- End of stack trace from previous location ---

fixes #56894

@adamsitnik adamsitnik added this to the 6.0.0 milestone Aug 11, 2021
@ghost
Copy link

ghost commented Aug 11, 2021

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

In #57212, I've validated that when async WriteFile operation fails with ERROR_OPERATION_ABORTED, the reported number of transferred bytes can be different than zero. Moreover, its value can be bigger than the number of bytes that we have requested to transfer when the operation was started, so we can assume that this value is always invalid in such case and just use zero instead.

Process terminated. Assertion failed.
Callback returned 995 error and 1547079704 bytes
   at Microsoft.Win32.SafeHandles.SafeFileHandle.OverlappedValueTaskSource.Complete(UInt32 errorCode, UInt32 numBytes) in /_/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs:line 198
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pNativeOverlapped) in /_/src/coreclr/System.Private.CoreLib/src/System/Threading
System.IO.Tests.FileStream_WriteAsync_AsyncWrites.TriggerTheProblemAsync [FAIL]
  System.Exception : The error code was 995 and numBytes was 189216864
  Stack Trace:
    /_/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs(101,0): at Microsoft.Win32.SafeHandles.SafeFileHandle.OverlappedValueTaskSource.GetResult(Int16 token)
    /_/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs(96,0): at Microsoft.Win32.SafeHandles.SafeFileHandle.OverlappedValueTaskSource.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
    /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs(251,0): at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
    --- End of stack trace from previous location ---
    /_/src/libraries/System.IO.FileSystem/tests/FileStream/WriteAsync.cs(131,0): at System.IO.Tests.FileStream_AsyncWrites.WriteAsyncCancelledFile(Int32 bufferSize, FileOptions fileOptions)
    /_/src/libraries/System.IO.FileSystem/tests/FileStream/WriteAsync.cs(110,0): at System.IO.Tests.FileStream_AsyncWrites.TriggerTheProblemAsync()
    --- End of stack trace from previous location ---

fixes #56894

Author: adamsitnik
Assignees: -
Labels:

area-System.IO

Milestone: 6.0.0

@ghost
Copy link

ghost commented Aug 11, 2021

Hello @adamsitnik!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

Copy link
Member

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

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

LGTM. Just a small optional suggestion to add a comment.

// 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?

@carlossanlop
Copy link
Member

The code only affects Windows. The CI failure happened in an unrelated OSX unit test which @jozkee fixed in #57235. This is good to merge.

@carlossanlop carlossanlop merged commit d839aac into dotnet:main Aug 11, 2021
@carlossanlop carlossanlop deleted the numBytesIsNotAlwaysZeroOnError branch August 11, 2021 23:06
@ghost ghost locked as resolved and limited conversation to collaborators Sep 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FileStream_WriteAsync_AsyncWrites.WriteAsyncCancelledFile test failed
4 participants