-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: SocketException: Connection reset by peer
PostPosted: Mon Aug 16, 2004 9:02 am 
Newbie

Joined: Sun Dec 28, 2003 11:10 am
Posts: 8
Hibernate version: 2.16

Mapping documents: not included - 1500 lines long

Code between sessionFactory.openSession() and session.close(): not necessary; works fine

Full stack trace of any exception that occurs:

java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:66)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:124)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:1664)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:1627)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1083)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1192)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2051)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1496)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeQuery(FilterPreparedStatement.java:68)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$2.executeQuery(C3P0PooledConnection.java:567)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)

Name and version of the database you are using: MySQL 4.1

Debug level Hibernate log excerpt: n/a

Configuration:

<hibernate-configuration>

<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://#host#/#name#?autoReconnect=true</property>
<property name="hibernate.connection.username">#user#</property>
<property name="hibernate.connection.password">#pass#</property>
<property name="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.max_fetch_depth">3</property>
<property name="hibernate.cache.provider_class">net.sf.hibernate.cache.OSCacheProvider</property>

<property name="hibernate.connection.provider_class">net.sf.hibernate.connection.C3P0ConnectionProvider</property>
<property name="c3p0.minPoolSize">2</property>
<property name="c3p0.maxPoolSize">10</property>
<property name="c3p0.timeout">300</property>
<property name="c3p0.max_statement">50</property>
<property name="c3p0.idle_test_period">300</property>
<property name="c3p0.max_size">100</property>

<mapping resource="hibernate.mapping.xml"/>
</session-factory>

</hibernate-configuration>

Question:

Everything works fine, most of the time. However, I'm using Hibernate in a standalone Swing application, which can go for hours (or even days) without being used, and it doesn't seem to want to re-establish dropped connections. It just throws a SocketException in the MySQL driver code, which is never passed back to the application. I've tried umpteen different ways of configuring the cache and database, I've tried adding ?autoConnect=true to the driver string, but it just doesn't work.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 9:11 am 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
Hello !

I dont know the C3P0 but DBCP (and probably C3PO too) requires you to "release" a connection.
That way the connection is passed back to the pool and will be monitored (by sending a dummy sql). If the connection is broken it will be reestablished.

And should it be "autoReconnect=true"?

Mario


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 9:27 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
<property name="c3p0.timeout">300</property>
<property name="c3p0.idle_test_period">300</property>

you're doing the test and the disconnection at the same time?
change
<property name="c3p0.idle_test_period">300</property>
to
<property name="c3p0.idle_test_period">150</property>
for example

if the test is negative, the connection is closed.
If the bdd closes the session (or if there is a network problem) between 2 tests, you'll have a socket error.

The only way to prevent this is to make a test at each use of a connection --> very expensive.

Be sure to configure MySql well

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.