Thread: Connection pooling problems

Connection pooling problems

From
Didrik Pinte
Date:
Hi,

I'm currently running a Tomcat 4.0.6 using a pooled data source as a JNDI
ressource (using the jakarta commons DBCP). The database is a PostgreSQL
7.3. The two computers are separated by a firewall. Everything works fine
except a strange problem I can't solve.

After a day on (it is not very regular), the application can't connect
anymore to the database, i'm getting the following error in the Tomcat's log:

An I/O error has occured while flushing the output - Exception:
java.net.SocketException: Connection reset by peer: socket write error
Stack Trace:

java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite(Native Method)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:96)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:72)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:130)
    at org.postgresql.PG_Stream.flush(PG_Stream.java:352)
    ...

In the postgres log, i'm reading :

Feb  3 21:10:47 XXXXXXX postgres[9934]: [4] LOG:  pq_recvbuf: recv()
failed: Connection reset by peer

My JNDI ressource is configured like that :

  <Resource name="jdbc/refPG" auth="Container" type="javax.sql.DataSource" />
                <ResourceParams name="jdbc/refPG">
                   <parameter>
                      <name>username</name>
                      <value>myusername</value>
                   </parameter>
                   <parameter>
                      <name>password</name>
                      <value>*******</value>
                   </parameter>
                   <parameter>
                      <name>driverClassName</name>
                      <value>org.postgresql.Driver</value>
                   </parameter>
                   <parameter>
                      <name>url</name>
                      <value>jdbc:postgresql://hostname/db</value>
                   </parameter>
                   <parameter>
                      <name>factory</name>
                      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
                   </parameter>
                   <parameter>
                      <name>maxActive</name>
                      <value>50</value>
                   </parameter>
                   <parameter>
                      <name>maxIdle</name>
                      <value>10</value>
                   </parameter>
                   <parameter>
                      <name>maxWait</name>
                      <value>10000</value>
                   </parameter>
                   <parameter>
                      <name>removeAbandoned</name>
                      <value>true</value>
                   </parameter>
                   <parameter>
                      <name>removeAbandonedTimeout</name>
                      <value>60</value>
                   </parameter>
                   <parameter>
                      <name>logAbandoned</name>
                      <value>true</value>
                   </parameter>
                </ResourceParams>


Do someone knows why I receive such an error ? I have no information in my
firewall log about denying access, but I suspect the configuration of the
pool being the origin of it. Maybe do I have to use
org.postgresql.jdbc2.optional.PooledDataSource in place of
org.postgresql.Driver in my configuration ?

Any help is welcome.

Thanks

Didrik Pinte
Adhoc Solutions
www.adhocsolutions.com



**** DISCLAIMER ****
This e-mail and any attachments thereto may contain information
which is confidential and/or protected by intellectual property
rights and are intended for the sole use of the recipient(s) named above.
Any use of the information contained herein (including, but not limited to,
total or partial reproduction, communication or distribution in any form)
by persons other than the designated recipient(s) is prohibited.
If you have received this e-mail in error, please notify the sender
and delete the material from any computer.
Thank you for your cooperation.



Re: Connection pooling problems

From
Tom Lane
Date:
Didrik Pinte <dp@adhoc.be> writes:
> I'm currently running a Tomcat 4.0.6 using a pooled data source as a JNDI
> ressource (using the jakarta commons DBCP). The database is a PostgreSQL
> 7.3. The two computers are separated by a firewall. Everything works fine
> except a strange problem I can't solve.
> After a day on (it is not very regular), the application can't connect
> anymore to the database, i'm getting the following error in the Tomcat's log:

Is it possible that the application does nothing with the database for
an hour or so before the connection is lost?  If there's no traffic for
awhile, it could be that the firewall is dropping the connection.

            regards, tom lane

Re: Connection pooling problems

From
Didrik Pinte
Date:
At 04:18  2/4/2003 -0500, Tom Lane wrote:
>Is it possible that the application does nothing with the database for
>an hour or so before the connection is lost?  If there's no traffic for
>awhile, it could be that the firewall is dropping the connection.
>
>                         regards, tom lane

Sure it's possible, but how can i prevent the error ? I think it's the job
of the PooledDataSource and not mine. Maybe they are some configuration
option I did not set well.


Didrik Pinte



**** DISCLAIMER ****
This e-mail and any attachments thereto may contain information
which is confidential and/or protected by intellectual property
rights and are intended for the sole use of the recipient(s) named above.
Any use of the information contained herein (including, but not limited to,
total or partial reproduction, communication or distribution in any form)
by persons other than the designated recipient(s) is prohibited.
If you have received this e-mail in error, please notify the sender
and delete the material from any computer.
Thank you for your cooperation.



Re: Connection pooling problems

From
Curt Sampson
Date:
On Tue, 4 Feb 2003, Didrik Pinte wrote:

> At 04:18  2/4/2003 -0500, Tom Lane wrote:
> >Is it possible that the application does nothing with the database for
> >an hour or so before the connection is lost?  If there's no traffic for
> >awhile, it could be that the firewall is dropping the connection.
>
> Sure it's possible, but how can i prevent the error ?

If it's the firewall, reconfigure it so that it doesn't need to keep
state for TCP connections between the two machines.

> I think it's the job of the PooledDataSource and not mine.
> Maybe they are some configuration option I did not set well.

There may be a configuration option that has the pool do something
simple on a connection every once in a while to keep it from being
completely idle, but then again, there may not. It's not something
you'd typically need or want.

cjs
--
Curt Sampson  <cjs@cynic.net>   +81 90 7737 2974   http://www.netbsd.org
    Don't you know, in this new Dark Age, we're all light.  --XTC