Skip to content

Commit 037af01

Browse files
Clarify CookieContainer thread-safety (#11171)
* Clarify CookieContainer thread-safety * better text * Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> * Use remarks section only * Update xml/System.Net/CookieContainer.xml --------- Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
1 parent 8965ddb commit 037af01

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

xml/System.Net/CookieContainer.xml

+8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@
7777
7878
The <xref:System.Net.CookieContainer> has three properties that govern the volume of the content of the container: <xref:System.Net.CookieContainer.Capacity%2A>, <xref:System.Net.CookieContainer.MaxCookieSize%2A>, and <xref:System.Net.CookieContainer.PerDomainCapacity%2A>. These values have the default settings of 300, 4096, and 20 respectively. When a <xref:System.Net.Cookie> is added to the container, these properties are used to determine whether a <xref:System.Net.Cookie> already contained in the <xref:System.Net.CookieContainer> should be discarded to make room for the new one. The <xref:System.Net.CookieContainer> keeps track of each addition to ensure that neither the <xref:System.Net.CookieContainer.Capacity%2A> nor the <xref:System.Net.CookieContainer.PerDomainCapacity%2A> limits are exceeded. If one or both are exceeded, then <xref:System.Net.Cookie> instances held by the <xref:System.Net.CookieContainer> are removed. First, any expired <xref:System.Net.Cookie> is removed. If further capacity must be recaptured, then the least-recently used <xref:System.Net.CookieCollection> is purged.
7979
80+
## Thread Safety
81+
82+
The methods for adding and retrieving <xref:System.Net.Cookie> instances to and from a <xref:System.Net.CookieContainer> are thread-safe and can be used concurrently from multiple threads.
83+
84+
> [!NOTE]
85+
> Regardless of thread-safety, unanticipated sharing of <xref:System.Net.CookieContainer> instances can lead to issues when working with <xref:System.Net.Http.HttpClient> and <xref:System.Net.Http.HttpClientHandler> or <xref:System.Net.Http.SocketsHttpHandler>, since parts of the application that aren't intended to share cookies with each other might inadvertently do so.
86+
> It is not recommended to use cookies together with <xref:System.Net.Http.IHttpClientFactory>.
87+
8088
]]></format>
8189
</remarks>
8290
<altmember cref="T:System.Net.Cookie" />

0 commit comments

Comments
 (0)