runtime: Memory leak in HttpClient
Description
I have a script that iterates over a large number of URLs and makes a GET request for each URL using async tasks. With parallelism set at 100 and with 15K URLs a 1 vCPU / 2GB RAM AWS instance runs out of memory.
Reproduction Steps
Added a project which can be used to reproduce the issue: https://github.com/jordinl/dotnet-http-client-memory-leak
The two only important files are the main script which reads the urls.txt file and makes the requests concurrently.
Running the program with CONCURRENCY=100 and LIMIT=15000 on a 1 vCPU / 2GB RAM AWS instance causes the instance to run out of memory. Even running it with smaller values it’s obvious that the memory keeps increasing.
Expected behavior
AWS instance not to run out of memory.
Actual behavior
Memory grows indefinitely.
Regression?
No response
Known Workarounds
No response
Configuration
- .NET 8
- OS: Linux 6.10 / Fedora 39 and Linux 6.8 / Ubuntu 24.04
- x86_64
Other information
Tried a couple of other things with the same results:
- Using
IHttpClientFactoryinstead of a singleHttpClient. var tasks = urls.Select(async url => ...to launch each task and then callawait Task.WhenAll(tasks)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 19 (10 by maintainers)
@rzikm I uploaded a pcap to https://github.com/dotnet/runtime/issues/109600