Thread: "Something unusual has occured" error using PostgreSQL 8.2 with Apache Commons DBCP 1.2.2

Hi -

I'm getting a rather disturbing exception that I really hope someone can
help me out with.

To start, I'm putting together a Java client-server app, where the
server side talks to a PostgreSQL database via an Apache Commons DBCP
link for connection pooling.  Using the code I've included below, I'm
able to establish a connection, get database metadata, and execute
stored functions perfectly well PROVIDING I DON'T try to call
getConnection() again without closing the first connection beforehand.
(but it seems to me that doing that ought to work alright, because if I
call getConnection() a second time, shouldn't the DBCP code just pull a
new connection from the pool, and not, instead, throw this exception?)

To recap.  This works:

Connection conn = ConnectionPool.getConnection();    // this
ConnectionPool class is one I wrote, see below for details
// do stuff with this connection
ConnectionPool.close(conn);                          // simply closes
the connection, catching any exceptions
conn = ConnectionPool.getConnection();               // get another
connection.  this works just fine now that
                                                     // the the
                                                     connection has been
                                                     closed before this
                                                     call

But if I try this, all hell breaks loose on the second call to
getConnection():

Connection conn = ConnectionPool.getConnection();
// do stuff with this connection
Connection conn2 = ConnectionPool.getConnection();   // the exception
below would be thrown inside here


EXCEPTION:
----------
org.postgresql.util.PSQLException: Something unusual has occured to
cause the driver to fail. Please report this exception.
        at org.postgresql.Driver.connect(Driver.java:276)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at
        org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:68)
        at
        org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
        at
        org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:840)
        at
        org.apache.commons.dbcp.PoolingDriver.connect(PoolingDriver.java:176)

        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at
        myproject.db.ConnectionPool.getConnection(ConnectionPool.java:136)


RELATED CODE:
-------------

This is the code I use to create the connection pool and register the
driver (in my ConnectionPool constructor) - note that this works insofar
as I can connect to the database and get metadata and do queries and
stuff, so I don't think this code is screwy, but who knows?):

    // some unrelated stuff up here
    ...
    GenericObjectPool pool = new GenericObjectPool(null);
    pool.setMinIdle(5);
    pool.setMaxIdle(10);
    pool.setMaxActive(30);
    pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
    pool.setMaxWait(1000 * 60 * 5);
    pool.setSoftMinEvictableIdleTimeMillis(1000 * 60 * 30);
    pool.setTimeBetweenEvictionRunsMillis(1000 * 60 * 10);

    Properties props = new Properties();
    props.setProperty("user", "testuser");
    props.setProperty("password", "testpass");

    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
        "jdbc:postgresql://localhost:5432/testdb", props);

    PoolableConnectionFactory poolableConnectionFactory =
        new PoolableConnectionFactory(connectionFactory,
        pool, null, null, false, false);

    PoolingDriver driver = new PoolingDriver();
    driver.registerPool("mydb", pool);
    ...

------------------------------------------------------------------------

Now, when I want to retrieve a connection, I call
ConnectionPool.getConnection(), which is where the problem occurs.  Note
that line 136 (from the stack trace above) is the "Connection conn =
DriverManager..." line in the code below:

    public static Connection getConnection() throws SQLException {
        try {
            Connection conn = DriverManager.getConnection(
                "jdbc:apache:commons:dbcp:mydb");
            return conn;
        } catch (SQLException sqle) {
            System.out.println(sqle.getMessage());
            sqle.printStackTrace();
            throw sqle;
        }
    }

------------------------------------

Lastly, here are the versions of the relevant software I'm using:
- PostgreSQL 8.2.4
- PostgreSQL JDBC driver 8.2-506.jdbc4
- Java 2 SE 1.6.0_02
- Jakarta Commons Pool 1.3
- Jakarta Commons DBCP 1.2.2
- Microsoft Windows XP SP2


On a possibly related note, I read in the Apache Commons DBCP README
that says:
"This release of JDBC compiles with and supports JDK 1.3 (JDBC 2.0) and
JDK 1.4-1.5 (JDBC 3.0). JDK 1.6 (JDBC 4.0) is not supported by this
release."  I'd like to try using PostgreSQL's JDBC3 drivers, but the
site says that if I'm using Java 1.6 I shouldn't use that, but should
use their JDBC4 drivers instead.  Any thoughts?

Thanks a lot for any help you can provide!

Regards,

Matt Storer

Matthew Storer wrote:
> To start, I'm putting together a Java client-server app, where the
> server side talks to a PostgreSQL database via an Apache Commons DBCP
> link for connection pooling.  Using the code I've included below, I'm
> able to establish a connection, get database metadata, and execute
> stored functions perfectly well PROVIDING I DON'T try to call
> getConnection() again without closing the first connection beforehand.
> (but it seems to me that doing that ought to work alright, because if I
> call getConnection() a second time, shouldn't the DBCP code just pull a
> new connection from the pool, and not, instead, throw this exception?)

Can you reduce it to a self-contained test case? That way others can
test and help with it as well.

> EXCEPTION:
> ----------
> org.postgresql.util.PSQLException: Something unusual has occured to
> cause the driver to fail. Please report this exception.
>         at org.postgresql.Driver.connect(Driver.java:276)
>         at java.sql.DriverManager.getConnection(Unknown Source)
>         at java.sql.DriverManager.getConnection(Unknown Source)
>         at
>
org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:68)
>         at
>         org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
>         at
>         org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:840)
>         at
>         org.apache.commons.dbcp.PoolingDriver.connect(PoolingDriver.java:176)
>
>         at java.sql.DriverManager.getConnection(Unknown Source)
>         at java.sql.DriverManager.getConnection(Unknown Source)
>         at
>         myproject.db.ConnectionPool.getConnection(ConnectionPool.java:136)

Is that the whole stack trace? The stack trace of the underlying
exception should be there as well.

--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com

Matthew Storer wrote:
> I'm getting a rather disturbing exception that I really hope
> someone can help me out with.

Sorry, but:

> On a possibly related note, I read in the Apache Commons
> DBCP README that says: "This release of JDBC compiles
> with and supports JDK 1.3 (JDBC 2.0) and JDK 1.4-1.5
> (JDBC 3.0). JDK 1.6 (JDBC 4.0) is not supported by this
> release."  I'd like to try using PostgreSQL's JDBC3
> drivers, but the site says that if I'm using Java 1.6
> I shouldn't use that, but should use their JDBC4 drivers
> instead.  Any thoughts?

I understand this to mean: "JDK 1.6 is not supported".

You should probably try with a different JDK.

Yours,
Laurenz Albe

Re: "Something unusual has occured" error using PostgreSQL 8.2 with Apache Commons DBCP 1.2.2

From
Iván Velamazán González
Date:
Hello to everybody:

Matthew Storer escribió:
> On a possibly related note, I read in the Apache Commons DBCP README
> that says:
> "This release of JDBC compiles with and supports JDK 1.3 (JDBC 2.0) and
> JDK 1.4-1.5 (JDBC 3.0). JDK 1.6 (JDBC 4.0) is not supported by this
> release."  I'd like to try using PostgreSQL's JDBC3 drivers, but the
> site says that if I'm using Java 1.6 I shouldn't use that, but should
> use their JDBC4 drivers instead.  Any thoughts?
>
Try playing with the javac "-source" option to set your source level to
1.5. That error drove me crazy for a while untill I set up my code to be
compatible with Java 1.5.

--
Iván Velamazán González


Hi Heikki -

I think I should be able to put together a simple test class that
demonstrates the behavior, that is, assuming the problem is in fact with
the code in question.

In any case, after I got home yesterday I tried to implement a pool
using a BasicDataSource object instead of what I was doing with the
PoolingDriver, and I haven't run into any problems at all with that.
I'm able to open new connections until all available are full, at which
point it blocks until one is freed, just like I'd expect it to do.

Still using J2SE 1.6 with Postgre's jdbc4 drivers.  go figure.

Do you still want me to post an example class that demonstrates the bug?
 I don't need a solution any more personally, but if you want to find
the bug for bug-squashing's sake, I can throw one together and post it
in the near-term.

take care, and thanks to all for the quick replies -

Matt

On Tue, 23 Oct 2007 19:13:53 +0100, "Heikki Linnakangas"
<heikki@enterprisedb.com> said:
> Matthew Storer wrote:
> > To start, I'm putting together a Java client-server app, where the
> > server side talks to a PostgreSQL database via an Apache Commons DBCP
> > link for connection pooling.  Using the code I've included below, I'm
> > able to establish a connection, get database metadata, and execute
> > stored functions perfectly well PROVIDING I DON'T try to call
> > getConnection() again without closing the first connection beforehand.
> > (but it seems to me that doing that ought to work alright, because if I
> > call getConnection() a second time, shouldn't the DBCP code just pull a
> > new connection from the pool, and not, instead, throw this exception?)
>
> Can you reduce it to a self-contained test case? That way others can
> test and help with it as well.
>
> > EXCEPTION:
> > ----------
> > org.postgresql.util.PSQLException: Something unusual has occured to
> > cause the driver to fail. Please report this exception.
> >         at org.postgresql.Driver.connect(Driver.java:276)
> >         at java.sql.DriverManager.getConnection(Unknown Source)
> >         at java.sql.DriverManager.getConnection(Unknown Source)
> >         at
> >
org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:68)
> >         at
> >         org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
> >         at
> >         org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:840)
> >         at
> >         org.apache.commons.dbcp.PoolingDriver.connect(PoolingDriver.java:176)
> >
> >         at java.sql.DriverManager.getConnection(Unknown Source)
> >         at java.sql.DriverManager.getConnection(Unknown Source)
> >         at
> >         myproject.db.ConnectionPool.getConnection(ConnectionPool.java:136)
>
> Is that the whole stack trace? The stack trace of the underlying
> exception should be there as well.
>
> --
>   Heikki Linnakangas
>   EnterpriseDB   http://www.enterprisedb.com

Matthew Storer wrote:
> Do you still want me to post an example class that demonstrates the bug?
>  I don't need a solution any more personally, but if you want to find
> the bug for bug-squashing's sake, I can throw one together and post it
> in the near-term.

Well, if it's not much trouble for you, it would be nice. I doubt it's a
real bug, though.

--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com