[DBCP] connections not properly closed

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[DBCP] connections not properly closed

Martin Wingert
I'm running dbcp 1.2.2 and mysql-connector-java-5.1.6 on a test system.

Just found that the system after running a couple of hours got an
exception in the log files when trying to create a new database
connection:
java.net.SocketException: Too many open files

Checked the list of open files (lsof) and got a long list:
java 10659 admin 6u sock 0,4 1555102 can't identify protocol

The PID is the jvm running our system.

Found that the MySQL setting wait_timeout (that closes idle
connections after the configured time) was set to 60 seconds by
accident. So it seems that when MySQL closes an idle connection
somehow the JDBC connection in the database pool isn't closed properly
leaving the file descriptor open (this is a test system so there are
many idle connections).


This is the code I use to setup my pool:

GenericObjectPool m_generic_objectpool = new GenericObjectPool();
m_generic_objectpool.setMaxActive(connection_timeout);
m_generic_objectpool.setMaxWait(max_wait);
m_generic_objectpool.setTestOnBorrow(true);
m_generic_objectpool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
   
ConnectionFactory connectionFactory = new
DriverManagerConnectionFactory(full_url,conProp);

AbandonedConfig ab_conf = new AbandonedConfig();
ab_conf.setRemoveAbandonedTimeout(m_dbpool_abandoned_timeout);
ab_conf.setRemoveAbandoned(m_dbpool_close_abandoned);

String validation_query = new String("SELECT 1");
new PoolableConnectionFactory(connectionFactory,m_generic_objectpool,null,validation_query,false,true,ab_conf);
   
PoolingDataSource data_source = new PoolingDataSource(m_generic_objectpool);


Thankful for any help

BR // Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [DBCP] connections not properly closed

wesclark
Set the "testWhileIdle" to test a few connections every so often.  It
will eject dead connections from the pool.

-----Original Message-----
From: Martin Wingert [mailto:[hidden email]]
Sent: Tuesday, September 30, 2008 8:01 AM
To: [hidden email]
Subject: [DBCP] connections not properly closed

I'm running dbcp 1.2.2 and mysql-connector-java-5.1.6 on a test system.

Just found that the system after running a couple of hours got an
exception in the log files when trying to create a new database
connection:
java.net.SocketException: Too many open files

Checked the list of open files (lsof) and got a long list:
java 10659 admin 6u sock 0,4 1555102 can't identify protocol

The PID is the jvm running our system.

Found that the MySQL setting wait_timeout (that closes idle connections
after the configured time) was set to 60 seconds by accident. So it
seems that when MySQL closes an idle connection somehow the JDBC
connection in the database pool isn't closed properly leaving the file
descriptor open (this is a test system so there are many idle
connections).


This is the code I use to setup my pool:

GenericObjectPool m_generic_objectpool = new GenericObjectPool();
m_generic_objectpool.setMaxActive(connection_timeout);
m_generic_objectpool.setMaxWait(max_wait);
m_generic_objectpool.setTestOnBorrow(true);
m_generic_objectpool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAU
STED_BLOCK);
   
ConnectionFactory connectionFactory = new
DriverManagerConnectionFactory(full_url,conProp);

AbandonedConfig ab_conf = new AbandonedConfig();
ab_conf.setRemoveAbandonedTimeout(m_dbpool_abandoned_timeout);
ab_conf.setRemoveAbandoned(m_dbpool_close_abandoned);

String validation_query = new String("SELECT 1"); new
PoolableConnectionFactory(connectionFactory,m_generic_objectpool,null,va
lidation_query,false,true,ab_conf);
   
PoolingDataSource data_source = new
PoolingDataSource(m_generic_objectpool);


Thankful for any help

BR // Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [DBCP] connections not properly closed

Martin Wingert
Thanks for the tip Wes. Saw the mail conversation from the 17 to 19
Sep about what seems to be a similar issue and your response there.

I would like to remove testOnBorrow since it seems very expensive (as
said in the mail conversation I mention above) but I'm a bit afraid of
getting "dead" connections from the pool. Since the system I have put
the db pool in is pretty big I'm not eager to go through all use of
connections and make them handle that scenario.

I'll change to testWhileIdle and run some tests.

BR // Martin



On Tue, Sep 30, 2008 at 5:16 PM, Wes Clark <[hidden email]> wrote:

> Set the "testWhileIdle" to test a few connections every so often.  It
> will eject dead connections from the pool.
>
> -----Original Message-----
> From: Martin Wingert [mailto:[hidden email]]
> Sent: Tuesday, September 30, 2008 8:01 AM
> To: [hidden email]
> Subject: [DBCP] connections not properly closed
>
> I'm running dbcp 1.2.2 and mysql-connector-java-5.1.6 on a test system.
>
> Just found that the system after running a couple of hours got an
> exception in the log files when trying to create a new database
> connection:
> java.net.SocketException: Too many open files
>
> Checked the list of open files (lsof) and got a long list:
> java 10659 admin 6u sock 0,4 1555102 can't identify protocol
>
> The PID is the jvm running our system.
>
> Found that the MySQL setting wait_timeout (that closes idle connections
> after the configured time) was set to 60 seconds by accident. So it
> seems that when MySQL closes an idle connection somehow the JDBC
> connection in the database pool isn't closed properly leaving the file
> descriptor open (this is a test system so there are many idle
> connections).
>
>
> This is the code I use to setup my pool:
>
> GenericObjectPool m_generic_objectpool = new GenericObjectPool();
> m_generic_objectpool.setMaxActive(connection_timeout);
> m_generic_objectpool.setMaxWait(max_wait);
> m_generic_objectpool.setTestOnBorrow(true);
> m_generic_objectpool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAU
> STED_BLOCK);
>
> ConnectionFactory connectionFactory = new
> DriverManagerConnectionFactory(full_url,conProp);
>
> AbandonedConfig ab_conf = new AbandonedConfig();
> ab_conf.setRemoveAbandonedTimeout(m_dbpool_abandoned_timeout);
> ab_conf.setRemoveAbandoned(m_dbpool_close_abandoned);
>
> String validation_query = new String("SELECT 1"); new
> PoolableConnectionFactory(connectionFactory,m_generic_objectpool,null,va
> lidation_query,false,true,ab_conf);
>
> PoolingDataSource data_source = new
> PoolingDataSource(m_generic_objectpool);
>
>
> Thankful for any help
>
> BR // Martin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]