2

I am using in my application HttpClient to call PatchAsync. I am trying to find out if this specific method is thread safe.

I found few sources which contradict each other. In this post: https://stackoverflow.com/questions/11178220/is-httpclient-safe-to-use-concurrently can be seen that PatchAsync, among other methods, is thread safe and there is link to msdn supposedly describing it. However today same link provides slightly different information, PatchAsync is no more in the list of thread safe methods while others still are.

The following methods are thread safe:

CancelPendingRequests DeleteAsync GetAsync GetByteArrayAsync GetStreamAsync GetStringAsync PostAsync PutAsync SendAsync

I also reviewed other posts suggested in the original post, for example: https://learn.microsoft.com/en-us/archive/blogs/henrikn/httpclient-httpclienthandler-and-webrequesthandler-explained Also here there is claim for thread safety:

A single HttpClient can be used to send as many HTTP requests as you want concurrently so in many scenarios you can just create one HttpClient and then use that for all your requests.

The problem is that this post is also pretty old, same as quote from .Net 4.5 MSDN.

So I am looking for a reliable source that can pour some light on this issue.

Pavel G.
  • 21
  • 1
  • 1
    I wonder why patch specifically can be unsafe. It's just another http verb, same as others. – Evk Nov 30 '22 at 16:21
  • 1
    Also if you look at source code then PatchAsync has exactly the same code as other methods (PutAsync etc) except request method is set to Patch (as one would expect, because there is nothing here to do differently). Probably they just forgot to mention it in documentation. – Evk Nov 30 '22 at 16:24
  • @Evk my thoughts exactly, just want to be sure, also seems a bit strange that it was on the list and now not, but just like you said, can't find any reason why it shouldn't be thread safe. – Pavel G. Nov 30 '22 at 17:48
  • If you really need documented proof - I'd fire an issue on their github asking for clarification. – Evk Nov 30 '22 at 18:02

0 Answers0