Thread: Strange JDBC problem

Strange JDBC problem

From
"Trygve Hardersen"
Date:
Hi
I'm experiencing a strange problem with the PostgreSQL JDBC driver on a
project I'm working on. Our setup is like this:

JRE 1.5
Apache Tomcat 5.5.17
Hibernate 3.1
C3P0 0.9.0
PostgreSQL 8.1-407.jdbc3
PostgreSQL 8.1.4

We exclusively use the JDBC connections through Hibernate, which again
uses the C3P0 connection pool. Normally this setup works fine, but on
Win2K SP4, we are experiencing strange problems.

Randomly we get "java.net.SocketException: Connection reset". The error
occurs in different parts of the application, but more frequently some
places, and mysteriously much more frequent when using Internet Explorer
6 (IE) on the same host as the web and DB server (localhost) than when
using Firefox (FF). In fact to begin with we thought the error only
occurred with IE, but we've also seen it happen with FF and Opera
sometimes, but very rarely.

There is nothing in our architecture that links the browser to the JDBC
connection, so I cannot explain why the error almost exclusively occurs
with IE. Even more strangely in not able to reproduce the error when
debugging the JDBC driver (by setting loglevel=2 on the connection URL),
nor when running against a DB on a different server, or when running
Tomcat on a different server using the DB on the affected server. The
application also supports MySQL and we're not seeing this error there.
We've also not seen the error Windows XP.

Here is the stack trace from the "Connection reset" exception. For the
sake of readability I removed some parts which I think is of no
significance:

01-09-2006 07:50:02,071  WARN JDBCExceptionReporter: SQL Error: 0,
SQLState: 08006
01-09-2006 07:50:02,071 ERROR JDBCExceptionReporter: An I/O error
occured while sending to the backend.
01-09-2006 07:50:02,081 ERROR [jsp]: Servlet.service() for servlet jsp
threw exception
org.hibernate.exception.JDBCConnectionException: could not initialize a
collection: [mypackage.pojo.modules.department.Department.children#827]

... Removed

Caused by: org.postgresql.util.PSQLException: An I/O error occured while
sending to the backend.
        at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:
214)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Stateme
nt.java:452)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdb
c2Statement.java:354)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2St
atement.java:258)
        at
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxy
PreparedStatement.java:76)
        at
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139
)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
        at org.hibernate.loader.Loader.doQuery(Loader.java:662)
        at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loade
r.java:224)
        at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
        ... 89 more
Caused by: java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:168)
        at
java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
        at
java.io.BufferedInputStream.read(BufferedInputStream.java:235)
        at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:256)
        at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImp
l.java:1163)
        at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:
188)
        ... 98 more

Does this make sense to any of you? It doesn't to me, but the error is
consistent, and I've tested this a lot. Any help or suggestions are much
appreciated.

Regards

Trygve Hardersen
Senior Software Engineer
Scala Nordic

Re: Strange JDBC problem

From
Guillaume Cottenceau
Date:
"Trygve Hardersen" <trygve.hardersen 'at' no.scala.com> writes:

> 01-09-2006 07:50:02,071 ERROR JDBCExceptionReporter: An I/O error
> occured while sending to the backend.

Might be a shot in the dark but.. This error also happened on me
because of some unsynchronized code concurrently accessing a
single prepared statement (setting values, performing the query,
retrieving the data). I am not sure how synchronizing is handled
when using hibernate (we don't). Maybe a different web client
trigger slightly different code paths or timings leading to the
problem.

--
Guillaume Cottenceau
Create your personal SMS or WAP Service - visit http://mobilefriends.ch/

Re: Strange JDBC problem

From
Mark Lewis
Date:
Wow, that sounds weird.

We once had an application bug with a web-app where Tomcat would give a
500 error sometimes when accessed by IE, but would work fine with other
browsers.  We used a packet sniffer and verified that the requests were
pretty much identical.

It turned out that the application had multiple frames, and IE requested
the different frames with a slightly different timing than Firefox or
Opera, and that slight timing difference exposed a race condition in a
library we were using (Struts).

Perhaps your app has a similar race condition somewhere.  You should be
able to check by putting in some kind of manual synchronization so you
only deal with one request at a time, and see if the problem goes away.
It's kind of a stretch, but it would explain why the problem only
happens on localhost with IE.

-- Mark


On Fri, 2006-09-01 at 15:40 +0200, Trygve Hardersen wrote:
> Hi
> I'm experiencing a strange problem with the PostgreSQL JDBC driver on a
> project I'm working on. Our setup is like this:
>
> JRE 1.5
> Apache Tomcat 5.5.17
> Hibernate 3.1
> C3P0 0.9.0
> PostgreSQL 8.1-407.jdbc3
> PostgreSQL 8.1.4
>
> We exclusively use the JDBC connections through Hibernate, which again
> uses the C3P0 connection pool. Normally this setup works fine, but on
> Win2K SP4, we are experiencing strange problems.
>
> Randomly we get "java.net.SocketException: Connection reset". The error
> occurs in different parts of the application, but more frequently some
> places, and mysteriously much more frequent when using Internet Explorer
> 6 (IE) on the same host as the web and DB server (localhost) than when
> using Firefox (FF). In fact to begin with we thought the error only
> occurred with IE, but we've also seen it happen with FF and Opera
> sometimes, but very rarely.
>
> There is nothing in our architecture that links the browser to the JDBC
> connection, so I cannot explain why the error almost exclusively occurs
> with IE. Even more strangely in not able to reproduce the error when
> debugging the JDBC driver (by setting loglevel=2 on the connection URL),
> nor when running against a DB on a different server, or when running
> Tomcat on a different server using the DB on the affected server. The
> application also supports MySQL and we're not seeing this error there.
> We've also not seen the error Windows XP.
>
> Here is the stack trace from the "Connection reset" exception. For the
> sake of readability I removed some parts which I think is of no
> significance:
>
> 01-09-2006 07:50:02,071  WARN JDBCExceptionReporter: SQL Error: 0,
> SQLState: 08006
> 01-09-2006 07:50:02,071 ERROR JDBCExceptionReporter: An I/O error
> occured while sending to the backend.
> 01-09-2006 07:50:02,081 ERROR [jsp]: Servlet.service() for servlet jsp
> threw exception
> org.hibernate.exception.JDBCConnectionException: could not initialize a
> collection: [mypackage.pojo.modules.department.Department.children#827]
>
> ... Removed
>
> Caused by: org.postgresql.util.PSQLException: An I/O error occured while
> sending to the backend.
>         at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:
> 214)
>         at
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Stateme
> nt.java:452)
>         at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdb
> c2Statement.java:354)
>         at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2St
> atement.java:258)
>         at
> com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxy
> PreparedStatement.java:76)
>         at
> org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139
> )
>         at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
>         at org.hibernate.loader.Loader.doQuery(Loader.java:662)
>         at
> org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loade
> r.java:224)
>         at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
>         ... 89 more
> Caused by: java.net.SocketException: Connection reset
>         at java.net.SocketInputStream.read(SocketInputStream.java:168)
>         at
> java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
>         at
> java.io.BufferedInputStream.read(BufferedInputStream.java:235)
>         at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:256)
>         at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImp
> l.java:1163)
>         at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:
> 188)
>         ... 98 more
>
> Does this make sense to any of you? It doesn't to me, but the error is
> consistent, and I've tested this a lot. Any help or suggestions are much
> appreciated.
>
> Regards
>
> Trygve Hardersen
> Senior Software Engineer
> Scala Nordic
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly

Re: Strange JDBC problem

From
"Trygve Hardersen"
Date:
> It turned out that the application had multiple frames, and IE
requested
> the different frames with a slightly different timing than Firefox or
> Opera, and that slight timing difference exposed a race condition in a
> library we were using (Struts).

We are in fact using multiple frames, and a "Hibernate Session &
Transaction per request" pattern. The result is that every "page"
generates multiple sessions and transactions. I tried to load only the
frame where the error usually occurs, and was unable to reproduce it, so
I think you hit the problem right on. Thanks a lot indeed! I'll try to
figure out a way around this.

Trygve