Skip to content

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

Merged
merged 6 commits into from
Feb 25, 2020

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Feb 21, 2020

Fix flaky test - #19242

@JamesNK JamesNK requested review from Tratcher and jkotalik February 21, 2020 21:56
@JamesNK JamesNK requested a review from analogrelay as a code owner February 21, 2020 21:56
@ghost ghost added the area-hosting label Feb 21, 2020
@JamesNK JamesNK added this to the 5.0.0-preview2 milestone Feb 21, 2020
_abortException = innerException;
_aborted = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why change this?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member Author

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);
                }
            }
        }

@JamesNK JamesNK merged commit 0b04260 into master Feb 25, 2020
@JamesNK JamesNK deleted the jamesnk/testclient-deflaky branch February 25, 2020 00:39
@amcasey amcasey added the area-hosting Includes Hosting label Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-hosting Includes Hosting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants