This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Repository navigation
Fix concurrency problem in FileWebRequest resulting in sporadic test failures - #12231
Merged
Merged
Conversation
ericeil
approved these changes
Sep 30, 2016
ericeil
left a comment
Contributor
There was a problem hiding this comment.
LGTM; just one question about the test.
| [Fact] | ||
| public async Task ConcurrentReadWrite_ResponseBlocksThenGetsNullStream() | ||
| { | ||
| if (!EnableConcurrentReadWriteTests) return; |
Contributor
There was a problem hiding this comment.
Kind of odd to have a test that does nothing. Can we move this test method into the derived class(es) that do support concurrent tests?
Member
Author
There was a problem hiding this comment.
Sure, I could create an intermediate base abstract class for the async ones and put it there.
…failures When I ported FileWebRequest/Response to corefx, I added a test that invokes GetRequestStreamAsync and GetResponseAsync to run concurrently with each other, as there's logic in the implementation (for reasons I'm not clear about) that suggests this should work, by blocking the latter until the former has completed. However, there's a race condition in the product that's causing the test to fail. FileWebRequest overrides the base's Begin/EndXx methods. It does not override the XxAsync methods. The base XxAsync implementations just wrap the Begin/End calls, but for whatever reason they also wrap it in a Task.Run. When FileWebRequest inherits that implementation, it causes problems for the test, as the marking that operations are in progress happens in the Begin overrides, which means they happen as part of the queued tasks from the base implementation. In rare cases where the BeginGetResponse task runs first, or where it runs in parallel with the BeginGetRequestStream task, problems occur. Three (simple) parts to the fix: 1. Override GetRequestStreamAsync/GetResponse so as to avoid the extra task the base class queues; it's unnecessary, causes this race condition, and adds a bit of overhead. I did some small refactoring to reuse all of the other logic between the XxAsync and Begin/EndXx overrides. 2. Make sure this concurrency test doesn't run with the synchronous methods, which would potentially manifest the same problem. 3. Since with (1) the Task-based APIs no longer wrap the Begin/End APIs, make sure all of the tests also run with the Begin/End APIs.
stephentoub
force-pushed
the
fix_fwr_concurrency
branch
from
October 1, 2016 01:48
038dabd to
da7b71d
Compare
picenka21
pushed a commit
to picenka21/runtime
that referenced
this pull request
Feb 18, 2022
…rrency Fix concurrency problem in FileWebRequest resulting in sporadic test failures Commit migrated from dotnet/corefx@344c008
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When I ported FileWebRequest/Response to corefx, I added a test that invokes GetRequestStreamAsync and GetResponseAsync to run concurrently with each other, as there's logic in the implementation (for reasons I'm not clear about) that suggests this should work, by blocking the latter until the former has completed. However, there's a race condition in the product that's causing the test to fail.
FileWebRequest overrides the base's Begin/EndXx methods. It does not override the XxAsync methods. The base XxAsync implementations just wrap the Begin/End calls, but for whatever reason they also wrap it in a Task.Run. When FileWebRequest inherits that implementation, it causes problems for the test, as the marking that operations are in progress happens in the Begin overrides, which means they happen as part of the queued tasks from the base implementation. In rare cases where the BeginGetResponse task runs first, or where it runs in parallel with the BeginGetRequestStream task, problems occur.
Three (simple) parts to the fix:
cc: @ericeil