-
Notifications
You must be signed in to change notification settings - Fork 10.4k
TestServer returns error with response when server ends with pending read #19249
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
Conversation
_abortException = innerException; | ||
_aborted = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put a for loop of 1,000,000 around the test logic to see if the error went away. There was a race condition about the order the properties are set that comes up here:
private void CheckAborted()
{
if (_aborted)
{
throw new IOException(string.Empty, _abortException);
}
}
You could get an IOException with a null inner exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of pattern scares me. Most people expect to set a bool like _aborted
at the at the top of a method called Aborted. Would it be better just to lock when checking aborted and setting the aborted Exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is locking necessary here? We just need to put the class in the right state before setting _aborted to true.
I could add a comment to Aborted if you'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eh, I think it's fine. Not worth rerunning CI for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If something is concurrently accessing this state then it should be locked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This?
private readonly object _abortLock = new object();
internal void Abort(Exception innerException)
{
Contract.Requires(innerException != null);
lock (_abortLock)
{
_abortException = innerException;
_aborted = true;
_pipe.Reader.CancelPendingRead();
}
}
private void CheckAborted()
{
lock (_abortLock)
{
if (_aborted)
{
throw new IOException(string.Empty, _abortException);
}
}
}
Fix flaky test - #19242