it-swarm.com.de

SQL-Fehler: 0, SQLState: 08S01 Kommunikationsverbindungsfehler

Ich erhalte diesen Fehler (nicht so häufig):

2013-05-08 16:44:35,786  WARN (JDBCExceptionReporter.Java:100) [org.hibernate.util.JDBCExceptionReporter, logExceptions] - SQL Error: 0, SQLState: 08S01
2013-05-08 16:44:35,786 ERROR (JDBCExceptionReporter.Java:101) [org.hibernate.util.JDBCExceptionReporter, logExceptions] - Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
2013-05-08 16:44:35,833 ERROR (AdminDaoImpl.Java:297) [com.myapp.admin.db.AdminDaoImpl, createFilePackage] - data-upload: Exception while adding new file package
org.hibernate.exception.JDBCConnectionException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.Java:97) [hibernate-core-3.3.2.GA.jar:3.3.2.GA]
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.Java:66) [hibernate-core-3.3.2.GA.jar:3.3.2.GA]
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.Java:52) [hibernate-core-3.3.2.GA.jar:3.3.2.GA]
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.Java:449) [hibernate-core-3.3.2.GA.jar:3.3.2.GA]
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.Java:167) [hibernate-core-3.3.2.GA.jar:3.3.2.GA]
    at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.Java:142) [hibernate-core-3.3.2.GA.jar:3.3.2.GA]
    at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.Java:85) [hibernate-core-3.3.2.GA.jar:3.3.2.GA]
    at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.Java:1354) [hibernate-core-3.3.2.GA.jar:3.3.2.GA]
    at com.myapp.admin.db.AdminDaoImpl. createFilePackage(AdminDaoImpl.Java:182) [AdminDaoImpl.class:na]
    at com.myapp.admin.ctrl.UploadController.processUploadZip(UploadController.Java:217) [UploadController.class:na]
    at Sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source) [na:na]
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:25) [na:1.6.0_35]
    at Java.lang.reflect.Method.invoke(Method.Java:597) [na:1.6.0_35]
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.Java:212) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.Java:126) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.Java:96) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.Java:617) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.Java:578) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.Java:80) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.Java:900) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.Java:827) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.Java:882) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.Java:789) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.Java:647) [servlet-api.jar:na]
    at javax.servlet.http.HttpServlet.service(HttpServlet.Java:728) [servlet-api.jar:na]
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:305) [catalina.jar:7.0.35]
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210) [catalina.jar:7.0.35]
    at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:222) [catalina.jar:7.0.35]
    at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:123) [catalina.jar:7.0.35]
    at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:472) [catalina.jar:7.0.35]
    at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:171) [catalina.jar:7.0.35]
    at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:99) [catalina.jar:7.0.35]
    at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:118) [catalina.jar:7.0.35]
    at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:407) [catalina.jar:7.0.35]
    at org.Apache.coyote.ajp.AjpProcessor.process(AjpProcessor.Java:200) [Tomcat-coyote.jar:7.0.35]
    at org.Apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.Java:589) [Tomcat-coyote.jar:7.0.35]
    at org.Apache.Tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.Java:310) [Tomcat-coyote.jar:7.0.35]
    at Java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.Java:886) [na:1.6.0_35]
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:908) [na:1.6.0_35]
    at Java.lang.Thread.run(Thread.Java:662) [na:1.6.0_35]
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Ich habe zwei Webanwendungen (Spring MVC + Hibernate + MySQL), die auf einem gemeinsam genutzten Server gehostet werden:

1) Haupt-App zum Anzeigen von Dateien zum Herunterladen (die über die Admin-App eingefügt wird)

2) Admin-App mit CRUD-Operationen

Dieser Fehler tritt irgendwann auf, wenn ich die Anwendung "admin" zum Hochladen von Dateien für die "Haupt" -App verwende. Nehmen wir an, nach erfolgreichem Hochladen/Verarbeiten von 100-120 Dateien/Anforderungen und bei jeder Anforderung, die die Datenbank mit 10-20 Einfügung/trifft. Aktualisierungsabfragen.

Hosting-Details:

Private Tomcat hosting
Java 1.6.0_35-b10
Tomcat 7.0.35
heap size 288MB
MySQL Server 5
commons-dbcp 1.2.2
mysql-connector-Java 5.1.9

Database + Hibernate + DBCP-Eigenschaften:

<bean id="dbDataSource" class="org.Apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="username" value="test" />
    <property name="password" value="test" />
    <property name="url" value="jdbc:mysql://localhost/my_database?useUnicode=yes&characterEncoding=UTF-8" />

    <!-- DBCP Connection Pool Settings -->
    <property name="defaultAutoCommit" value="true" />
    <property name="initialSize" value="10" />
    <property name="maxActive" value="500" />
    <property name="maxIdle" value="8" />
    <property name="minIdle" value="0" />
    <property name="maxWait" value="30000" />
    <property name="validationQuery" value="SELECT 1" />
    <property name="testOnBorrow" value="true" />
    <property name="testOnReturn" value="false" />
    <property name="testWhileIdle" value="false" />
    <property name="timeBetweenEvictionRunsMillis" value="-1" />
    <property name="numTestsPerEvictionRun" value="3" />
    <property name="minEvictableIdleTimeMillis" value="180000" />
    <property name="poolPreparedStatements" value="true" />
    <property name="maxOpenPreparedStatements" value="25" />
    <property name="accessToUnderlyingConnectionAllowed" value="false" />
    <property name="removeAbandoned" value="false" />
    <property name="removeAbandonedTimeout" value="300" />
    <property name="logAbandoned" value="false" />
</bean>

hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=none
hibernate.jdbc.batch_size=100
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=false
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.current_session_context_class=thread

Betroffener Code:

public String createFilePackage(FilePackage package) {
    String message = "";

    Session session = getSessionFactory().openSession();
    Transaction tx = null;
    try {
        tx = session.beginTransaction();

        // handling package, around 10-14 DB insert, 10 SELECT and 5 update queries on same session

        tx.commit();

    } catch(Exception e) {
        logger.error("file-upload: Exception while adding new font package", e);
        if(tx != null) { tx.rollback(); }
    } finally {
        session.close();
    }
    return message;
}

ratschläge, wie Sie dieses Problem lösen können?

12
spring_dev101

Die Kommunikationsverbindung zwischen dem Treiber und der Datenquelle, zu der der Treiber versucht hat, eine Verbindung herzustellen, ist fehlgeschlagen, bevor die Funktion die Verarbeitung abgeschlossen hat. Dies kann durch Paketabbrüche oder falsch konfigurierte Firewall/Switch verursacht werden. 

13
Maciej Cygan

Überprüfen Sie Ihre Serverkonfigurationsdatei /etc/mysql/my.cnf - Stellen Sie sicher, dass bind_address nicht auf 127.0.0.1 eingestellt ist. Setzen Sie es auf 0.0.0.0 oder kommentieren Sie es aus und starten Sie den Server erneut mit:

Sudo service mysql restart
3
morajp2000
0
Arthur