Reputation: 86
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.
[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
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.
Does jtds or EL leak Ports or connections? No.
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.
Upvotes: 3
Views: 358
Reputation: 38667
Solution by OP.
Hotfix: we configured our pool to use the same value for min/max to prevent EL from opening and closing connections dynamically.
More elaborated: we'll use an external connection pool, which allows us to define a pool for idle connections and a connection idle time e.g. DBCP with minEvictableIdleTimeMillis.
Upvotes: 1