1

I'm having a problem that we can only reproduce on a production server. Here is the stack trace:

Caused by: org.hibernate.exception.JDBCConnectionException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:2214)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
    at org.hibernate.loader.Loader.list(Loader.java:2090)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
    at com.dir.web.beans.clientpartners.dao.DaoClientPartnerImpl.getBrandAssignments(DaoClientPartnerImpl.java:268)
    ... 46 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
    at sun.reflect.GeneratedConstructorAccessor143.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3134)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1818)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2543)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1888)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
    at org.hibernate.loader.Loader.doQuery(Loader.java:662)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    at org.hibernate.loader.Loader.doList(Loader.java:2211)
    ... 53 more
Caused by: java.net.SocketException: Software caused connection abort: 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:65)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3119)
    ... 64 more

You can see the code that is throwing the exception:

public List<BrandAssignment> getBrandAssignments(String query) throws ClientPartnerException {
    Validate.notEmpty(query, "The query cannot be empty or null");
    List<BrandAssignment> brandAssignments = null;

    try {
        brandAssignments = getCurrentSession().createSQLQuery(query).addEntity(BrandAssignment.class).list();
        getCurrentSession().close();
    } catch (HibernateException hibernateException) {
        throw new ClientPartnerException("Error getting brand assignments with query: " + query, hibernateException);
    }

    return brandAssignments;

}

The getCurrentSession method basically asks the session factory for the current session and begins a transaction if no one started it before.

This is my configuration for Hibernate:

    <property name="c3p0.acquire_increment">1</property>
    <property name="c3p0.idle_test_period">5</property>
    <property name="c3p0.max_size">100</property>
    <property name="c3p0.max_statements">0</property>
    <property name="c3p0.min_size">10</property>
    <property name="c3p0.timeout">100</property>

    <property name="current_session_context_class">thread</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

The query looks like this:

SELECT DISTINCT brand_assig.brand_assignment_id, brand_assignment_name, brand_assig.date_created, brand_assig.date_modified, brand_assig.modified_by, brand_assig.client_division_id, brand_assig.business_category, brand_assig.country, brand_assig.region, brand_assig.office_alias, brand_assig.assignment_start_date, brand_assig.assignment_end_date, brand_assig.assignment_status, brand_assig.industry_experience, brand_assig.description, brand_assig.communication_disciplines, brand_assig.client_type 
FROM clnt_parent INNER JOIN clnt_partner INNER JOIN clnt_div INNER JOIN brand_assig 
ON client_division.client_division_id = brand_assig.client_division_id AND    client_partner.client_partner_id = client_division.client_partner_id AND    client_parent.client_parent_id = client_partner.client_parent_id 
WHERE ( MATCH (client_partner_name) AGAINST ('+nutrition*'IN BOOLEAN MODE) OR MATCH (client_parent_name) AGAINST ('+nutrition*'IN BOOLEAN MODE) OR MATCH (client_division_name) AGAINST ('+nutrition*'IN BOOLEAN MODE) OR MATCH (brand_assignment_name, industry_experience) AGAINST ('+nutrition*'IN BOOLEAN MODE)) AND brand_assig.assignment_end_date IS NOT NULL 
ORDER BY client_partner.client_partner_name 

The thing is I'm unable to reproduce the error in a development environment to test for a solution, and I'm not sure about what's causing the problem as I check the configuration and seems to be fine. Looking at the timeout set for MySql server is set by default in 8 hours. The error is happening very often in prod, but never in a dev environment. Anyone knows what might be causing the error and how can I reproduce this? Any possible solution? Thanks!

  • So given you are right about the piece of code where's the error text for the ClientPartnerException. First thing I'd be looking at is what was in query, see if anything strange was going on. – Tony Hopkinson Sep 10 '13 at 21:27
  • possible duplicate of [Official reasons for "Software caused connection abort: socket write error"](http://stackoverflow.com/questions/2126607/official-reasons-for-software-caused-connection-abort-socket-write-error) – user207421 Sep 10 '13 at 23:01
  • EJP, the post you are mentioning is too generic. I'm looking for a more specific answer here. – user2766373 Sep 11 '13 at 13:17
  • Tony, I posted the query. I don't see anything bad in it. Besides, it works well on other environments. – user2766373 Sep 11 '13 at 13:18

0 Answers0