title: Network error using eclipselink with internal connection pool
body: <p>We've implemented a JavaSE application using eclipselink with its internal connection pool feature. We've configured the default pool to use a minimum of 1 and a maximum of 10 connections. 
  After installing this application on a windows terminal server and running 50 simultaneous sessions for stress testing we've encountered the following exception on several sessions.</p>
  
  <pre><code>[EL Severe]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DatabaseException
  Internal Exception: java.sql.SQLException: Network error IOException: No buffer space available (maximum connections reached?): connect
  </code></pre>
  
  <p>We use jtds as driver to connect to MS SQL server. Using netstat showed that all dynamically available TCP ports (more than 16000) were consumed by connections to the SQL server in state TIMED_WAIT. </p>
  
  <p>Does jtds or EL leak Ports or connections? No.</p>
  
  <p>It turns out that our pool configuration was the problem. Our application often required more than one connection for asynchronous requests. The pool contained only one permanent connection (min). EL opened dynamically up to 10 more connections (max) but closed those connections immediately after executing one statement. jtds uses sockets to communicate with SQL server. Closing a socket requires about 4 minutes (tcp_time_wait_interval) until the port is available for the next connection.
  Slowly but surely the terminal server run out of available ports. </p>