Skip to content

Clarify CookieContainer thread-safety #11171

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions xml/System.Net/CookieContainer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@

]]></format>
</remarks>
<threadsafe>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a legit tag?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but looks like it cannot handle embedded <format> :( Will move the content to <remarks>.

<format type="text/markdown"><![CDATA[

## Thread Safety

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.

> [!NOTE]
> 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 might inadvertently do so.
> It is not recommended to use cookies together with <xref:System.Net.Http.IHttpClientFactory>.

]]></format>
</threadsafe>
<altmember cref="T:System.Net.Cookie" />
<altmember cref="T:System.Net.CookieCollection" />
<altmember cref="T:System.Net.CookieContainer" />
Expand Down