Ported code using httpWebRequest runs out of sockets


I have quickly ported some old code written wayback in the .NET 2.0 timeframe that we use for stress testing a webserver over to .NET core. It basically spawns ~30 threads then hammers the webserver with requests. The issue I am having is that after about 30k requests the system runs out of ports and so cannot spawn any new requests (all the sockets are sitting in TIME_WAIT).

This issue was solved in .NET by setting the connection limit to 100 in the httpWebRequest ServicePoint, but this is not an option for core yet AFAICT. Is there any other way to get around this issue which doesn’t involve rewriting all the code?


Probably a bit too late by now, but take a look at this

Issue caused by unnecessary disposing and instantiation of the HttpRequest object.

.NET Foundation Website | Blog | Projects | Code of Conduct