Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fix ReadAsync not returning when cancellation token fires during FlushAsync#31212

Merged
pakrym merged 3 commits intodotnet:masterfrom
pakrym:pakrym/fix-cancellation-hang
Jul 24, 2018
Merged

Fix ReadAsync not returning when cancellation token fires during FlushAsync#31212
pakrym merged 3 commits intodotnet:masterfrom
pakrym:pakrym/fix-cancellation-hang

Conversation

@pakrym
Copy link

@pakrym pakrym commented Jul 19, 2018

Fixes #31201

// AttachToken before completing reader awaiter in case cancellationToken is already completed
cancellationTokenRegistration = _writerAwaitable.AttachToken(cancellationToken, s_signalWriterAwaitable, this);

// If the writer is completed (which it will be most of the time) the return a completed ValueTask

Choose a reason for hiding this comment

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

nit: then return a completed ValueTask

}
});

Assert.True(Task.WaitAll(new [] { writer, reader, canceller }, TimeSpan.FromSeconds(30)), "Reader was not completed in reasonable time");

Choose a reason for hiding this comment

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

Isn't potentially spending 30 seconds on a single unit test too long? Does the test still work as intended if we change this to < 5 seconds?

Copy link
Author

Choose a reason for hiding this comment

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

Only if fails. I don't want to introduce the test that would be flaky on slower machines. In the successful case, it passes quickly.

var writer = Task.Run(async () =>
{
var cancellations = 0;
while (cancellations < 20)

Choose a reason for hiding this comment

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

Any particular reason for 20?

Copy link
Author

Choose a reason for hiding this comment

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

No, just a random number.

}
catch (OperationCanceledException)
{
cancellations ++;

Choose a reason for hiding this comment

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

nit: remove space

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.

4 participants