DEV Community

Discussion on: Updating a Record Using C# .NET and the Salesforce REST API

Collapse
 
rachelsoderberg profile image
Rachel Soderberg • Edited

You are absolutely right! I never ran into issues with exhausting the sockets because of how small my testing domain has been so far, but I can see how this would have bit me down the road in our production environment. So you not only saved me a headache later down the road, but I've updated my examples as well. Thank you friend!

In case anyone else is curious, here's what I learned!

HttpClient is intended to be instantiated once and re-used throughout the life of an application. Instantiating an HttpClient class for every request will exhaust the number of sockets available under heavy loads. This will result in SocketException errors.

Collapse
 
yucked profile image
Yucked

Cheers. Another thing I noticed. .Result can in some cases cause deadlocks, iirc. I would change method signature to asynchronous Task and await everything within methods body. Along with wrapping HttpRequestMessage in a using statement or simply using var request Update = ....