Skip to content

[release/7.0] Fix WebProxy Race Condition Issue #75246

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 5 commits into from
Sep 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Globalization;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Threading;

namespace System.Net
{
Expand Down Expand Up @@ -127,10 +128,9 @@ public bool UseDefaultCredentials

private void UpdateRegexList()
{
Regex[]? regexBypassList = null;
if (_bypassList is ChangeTrackingArrayList bypassList)
{
bypassList.IsChanged = false;
Regex[]? regexBypassList = null;
if (bypassList.Count > 0)
{
regexBypassList = new Regex[bypassList.Count];
Expand All @@ -139,9 +139,14 @@ private void UpdateRegexList()
regexBypassList[i] = new Regex((string)bypassList[i]!, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
}
}
}

_regexBypassList = regexBypassList;
_regexBypassList = regexBypassList;
bypassList.IsChanged = false;
}
else
{
_regexBypassList = null;
}
}

private bool IsMatchInBypassList(Uri input)
Expand Down Expand Up @@ -219,7 +224,10 @@ public ChangeTrackingArrayList() { }

public ChangeTrackingArrayList(ICollection c) : base(c) { }

public bool IsChanged { get; set; }
// While this type isn't intended to be mutated concurrently with reads, non-concurrent updates
// to the list might result in lazy initialization, and it's possible concurrent HTTP requests could race
// to trigger that initialization.
public volatile bool IsChanged;

// Override the methods that can add, remove, or change the regexes in the bypass list.
// Methods that only read (like CopyTo, BinarySearch, etc.) and methods that reorder
Expand Down