Skip to content

Commit b81eb4f

Browse files
github-actions[bot]liveansMihaZupanstephentoubkarelz
authored
[release/7.0] Fix WebProxy Race Condition Issue (#75246)
* Update: Fix Race Condition Issue * Update: Review changes * Update: Review change Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * Update: Add comment to volatile field Co-authored-by: Stephen Toub <stoub@microsoft.com> * Update src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs Co-authored-by: Karel Zikmund <karelz@microsoft.com> Co-authored-by: Ahmet Ibrahim Aksoy <aaksoy@microsoft.com> Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Karel Zikmund <karelz@microsoft.com>
1 parent 0090857 commit b81eb4f

File tree

1 file changed

+13
-5
lines changed
  • src/libraries/System.Net.WebProxy/src/System/Net

1 file changed

+13
-5
lines changed

src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Globalization;
99
using System.Runtime.Serialization;
1010
using System.Text.RegularExpressions;
11+
using System.Threading;
1112

1213
namespace System.Net
1314
{
@@ -127,10 +128,9 @@ public bool UseDefaultCredentials
127128

128129
private void UpdateRegexList()
129130
{
130-
Regex[]? regexBypassList = null;
131131
if (_bypassList is ChangeTrackingArrayList bypassList)
132132
{
133-
bypassList.IsChanged = false;
133+
Regex[]? regexBypassList = null;
134134
if (bypassList.Count > 0)
135135
{
136136
regexBypassList = new Regex[bypassList.Count];
@@ -139,9 +139,14 @@ private void UpdateRegexList()
139139
regexBypassList[i] = new Regex((string)bypassList[i]!, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
140140
}
141141
}
142-
}
143142

144-
_regexBypassList = regexBypassList;
143+
_regexBypassList = regexBypassList;
144+
bypassList.IsChanged = false;
145+
}
146+
else
147+
{
148+
_regexBypassList = null;
149+
}
145150
}
146151

147152
private bool IsMatchInBypassList(Uri input)
@@ -219,7 +224,10 @@ public ChangeTrackingArrayList() { }
219224

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

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

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

0 commit comments

Comments
 (0)