-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.2.4
-
Component/s: Connectivity, Error Handling
-
None
-
Environment:Windows 2012\2008 server
TcpStreamFactory both connect methods throw exception without disposing socket. Sockets collect in finalizer queue and stays there. After some time undisposed sockets consume all ephemeral ports.
Connect 103 line.
ConnectAsync 149 line.
Can be reproduced with this snippet:
Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
static void Main(string[] args) { Task.Run(() => { var listener = new TcpListener(IPAddress.Any, 15547); listener.Start(); var cc = new List<TcpClient>(); while (true) { cc.Add(listener.AcceptTcpClient()); Console.WriteLine("accepted"); } }); List<TcpClient> clients = new List<TcpClient>(); int count = 1000000; Parallel.ForEach(Enumerable.Range(0, count), v => { while (true) { try { var client = new TcpClient(); client.Connect("localhost", 15547); clients.Add(client); break; } catch (Exception e) { Console.WriteLine("clap"); Task.Delay(TimeSpan.FromSeconds(1)).Wait(); } } }); Console.ReadLine(); }