Thursday, January 4, 2018

DNS changed when using a single HttpClient

I blogged before about the fact that it is better to re-use your HttpClient object instead of disposing and creating a new one for every request.  There is however one caveat with a global HttpClient, and that is that DNS changes are not honored because the connections are re-used.

A solution is to set a connection timeout before your connection is released and recreated by using the ServicePointManager:

This will release the connection after 60 seconds.

No comments: