Urgent.News

What's breaking now, across thousands of outlets.

Tech

HttpClientFactory: Why new HttpClient() Is Killing Your App

Hey there, fellow C# developers! ๐Ÿ‘‹ Let me tell you a horror story. You're building a nice web service, everything works great in development, and then... production hits. Suddenly your app is throwing SocketException errors left and right. What happened? You probably did this: // DON'T DO THIS! using ( var client = new HttpClient ()) { var response = await client . GetAsync (โ€ฆ

C# developers often create an HttpClient instance with a using statement, but this leads to Socket Exhaustion. The problem occurs because disposing of HttpClient doesn't close sockets immediately; they enter a TIME_WAIT state for several minutes. A single Windows machine has only ~16,000 ephemeral ports, so under load, all sockets can be exhausted in just a few minutes. .NET Core 2.1 introduced IHttpClientFactory to solve this issue by pooling and reusing HttpMessageHandler instances, allowing proper DNS rotation.

To use it, addHttpClient() in Program.cs or Startup.cs, then create services with IHttpClientFactory. For pre-configured clients, use named clients by adding client = {BaseAddress, DefaultRequestHeaders, Timeout}. For typed clients, inject a fully configured HttpClient directly into your service. Additionally, you can customize handler lifetime, but be cautious with long lifetimes as IP changes can cause issues.

The best approach is to stop creating HttpClient instances manually and use IHttpClientFactory to manage connection pooling, avoiding socket exhaustion errors.

Written by urgent.news from Dev.to's reporting โ€” not their text. Machine-written โ€” may contain errors; check the original before relying on it.

Read the original at dev.to โ†’

More in Tech

How to Install an MCP Server from the Official Registry

SAFi comes already packaged to handle MCP tool installation, including its own registry search, which looks for MCP servers published at the official MCP registryโ€ฆ

  • SAFi must be installed and virtual environment activated
  • Search registry for package name and version
  • Install server using scripts/safimcp.py add [package name]

Linux Collaborative Directories

The Nautilus team doesn't want its data to be accessed by any of the other groups/teams due to security reasons and want their data to be strictly accessed by the sysops group of the team.

  • Nautilus team establishes Linux collaborative directory for sysops group.
  • Shared directory /sysops/data created on app server 2 in Stratos Datacenter.
  • Full access for sysops members, strict control over file permissions.

Stop Rewriting Your CV: Tailor One Base CV for Every Job Application

I used to keep six versions of my CV in one folder. CV_final.docx , CV_final_v2.docx , CV_final_REAL.docx . Every application meant twenty minutes of copy, paste and guilt โ€” and I still had no idea ifโ€ฆ

  • Create one base CV and tailor it for each job
  • Use CVSet tool to analyze, optimize, and tailor CVs
  • Scoring system evaluates CV across nine dimensions

More from Tuesday 1 September โ†’