title: How to cleanup sockets after mono-process crashes?
body: <p>I am creating a chat server in mono that should be able to have many sockets open. Before deciding on the architecture, I am doing a load test with mono. Just for a test, I created a small mono-server and mono-server that opens 100,000 sockets/connections and it works pretty well. </p>
  
  <p>I tried to hit the limit and at sometime the process crashes (of course).
  But what worries me is that if I try to restart the process, it directly gives "Unhandled Exception: System.Net.Sockets.SocketException: Too many open files". </p>
  
  <p>So I guess that somehow the filedescriptions(sockets) are kept open even when my process ends. Even several hours later it still gives this error, the only way I can deal with it is to reboot my computer. We cannot run into this kind of problem if we are in production without knowing how to handle it.</p>
  
  <p><strong>My question:</strong>
  Is there anything in Mono that keeps running globally regardless of which mono application is started, a kind of service I can restart without rebooting my computer? 
  Or is this not a mono problem but a unix problem, that we would run into even if we would program it in java/C++?</p>
  
  <p>I checked the following, but no mono processes alive, no sockets open and no files:</p>
  
  <pre><code>localhost:~ root# ps -ax | grep mono  
  1536 ttys002    0:00.00 grep mono
  </code></pre>
  
  <p>-</p>
  
  <pre><code>localhost:~ root# lsof | grep mono  
  (nothing)
  </code></pre>
  
  <p>-</p>
  
  <pre><code>localhost:~ root# netstat -a  
  Active Internet connections (including servers)  
  (no unusual ports are open)
  </code></pre>
  
  <p>For development I run under OSX 10.7.5. For production we can decide which platform to use.</p>