title: MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown
body: <p>Whenever I build a job in Hudson, it always fails right at the very end when trying to store the results in the database. The whole job usually takes around an hour to build and fail.</p>
  
  <p>The source files are stored on an SVN server and can be downloaded and edited locally. Once I verify that the job is able to build successfully locally, I commit any changes to the SVN. </p>
  
  <p>I recently switched to an ANT-based approach which aligns the ant target to match the convention reviewer. So I created a sonar.xml file that contains a target called sonar_scan, which is called in the build.xml file of the project.</p>
  
  <p>I have set the net_read_timeout, net_write_timeout and the innodb_lock_wait_timeout to 10 minutes, rather than their default values of 60 seconds or less. The wait_timeout is set to 8 hours, so I know that the wait_timeout is not the problem.</p>
  
  <ul>
  <li>The database I'm using is mysql version 5.6.25</li>
  <li>The version of Sonar I'm using is 5.1</li>
  </ul>
  
  <p>The full error message I receive is:</p>
  
  <pre><code>[sonar:sonar] 19:09:43.831 ERROR - JDBC commit failed    
  [sonar:sonar] com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.
      [sonar:sonar]   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_45]
      [sonar:sonar]   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_45]
      [sonar:sonar]   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_45]
      [sonar:sonar]   at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_45]
      [sonar:sonar]   at com.mysql.jdbc.Util.handleNewInstance(Util.java:377) ~[mysql-connector-java-5.1.34.jar:5.1.34]
      [sonar:sonar]   at com.mysql.jdbc.Util.getInstance(Util.java:360) ~[mysql-connector-java-5.1.34.jar:5.1.34]
      [sonar:sonar]   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) ~[mysql-connector-java-5.1.34.jar:5.1.34]
      [sonar:sonar]   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935) ~[mysql-connector-java-5.1.34.jar:5.1.34]
      [sonar:sonar]   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924) ~[mysql-connector-java-5.1.34.jar:5.1.34]
      [sonar:sonar]   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870) ~[mysql-connector-java-5.1.34.jar:5.1.34]
      [sonar:sonar]   at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1611) ~[mysql-connector-java-5.1.34.jar:5.1.34]
      [sonar:sonar]   at org.apache.commons.dbcp.DelegatingConnection.commit(DelegatingConnection.java:334) ~[sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.commit(PoolingDataSource.java:211) ~[sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:170) ~[sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:146) ~[sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.sonar.jpa.session.JpaDatabaseSession.commit(JpaDatabaseSession.java:83) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.sonar.jpa.session.JpaDatabaseSession.commitAndClose(JpaDatabaseSession.java:69) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.sonar.jpa.session.JpaDatabaseSession.stop(JpaDatabaseSession.java:64) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_45]
      [sonar:sonar]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_45]
      [sonar:sonar]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_45]
      [sonar:sonar]   at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_45]
      [sonar:sonar]   at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.stop(ReflectionLifecycleStrategy.java:96) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.stop(AbstractInjectionFactory.java:88) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.picocontainer.behaviors.AbstractBehavior.stop(AbstractBehavior.java:179) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.picocontainer.behaviors.Stored$RealComponentLifecycle.stop(Stored.java:141) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.picocontainer.behaviors.Stored.stop(Stored.java:118) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.picocontainer.DefaultPicoContainer.stopAdapters(DefaultPicoContainer.java:1047) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.picocontainer.DefaultPicoContainer.stop(DefaultPicoContainer.java:802) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.sonar.api.platform.ComponentContainer.stopComponents(ComponentContainer.java:123) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.sonar.api.platform.ComponentContainer.stopComponents(ComponentContainer.java:118) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.sonar.batch.bootstrapper.Batch.stop(Batch.java:107) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67) [sonar-batch-maven-compat-5.1.jar:na]
      [sonar:sonar]   at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48) [sonar-runner-batch1253226961910621726.jar:na]
      [sonar:sonar]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_45]
      [sonar:sonar]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_45]
      [sonar:sonar]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_45]
      [sonar:sonar]   at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_45]
      [sonar:sonar]   at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87) [sonar-ant-task-2.3.jar:na]
      [sonar:sonar]   at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75) [sonar-ant-task-2.3.jar:na]
      [sonar:sonar]   at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_45]
      [sonar:sonar]   at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69) [sonar-ant-task-2.3.jar:na]
      [sonar:sonar]   at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50) [sonar-ant-task-2.3.jar:na]
      [sonar:sonar]   at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102) [sonar-ant-task-2.3.jar:na]
      [sonar:sonar]   at org.sonar.runner.api.Runner.execute(Runner.java:100) [sonar-ant-task-2.3.jar:na]
      [sonar:sonar]   at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:51) [sonar-ant-task-2.3.jar:na]
      [sonar:sonar]   at org.sonar.ant.SonarTask.execute(SonarTask.java:46) [sonar-ant-task-2.3.jar:na]
      [sonar:sonar]   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) [ant.jar:1.9.2]
      [sonar:sonar]   at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[na:na]
      [sonar:sonar]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_45]
      [sonar:sonar]   at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_45]
      [sonar:sonar]   at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) [ant.jar:na]
      [sonar:sonar]   at org.apache.tools.ant.Task.perform(Task.java:348) [ant.jar:1.9.2]
      [sonar:sonar]   at org.apache.tools.ant.Target.execute(Target.java:435) [ant.jar:1.9.2]
      [sonar:sonar]   at org.apache.tools.ant.Target.performTasks(Target.java:456) [ant.jar:1.9.2]
      [sonar:sonar]   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393) [ant.jar:1.9.2]
      [sonar:sonar]   at org.apache.tools.ant.Project.executeTarget(Project.java:1364) [ant.jar:1.9.2]
      [sonar:sonar]   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) [ant.jar:na]
      [sonar:sonar]   at org.apache.tools.ant.Project.executeTargets(Project.java:1248) [ant.jar:1.9.2]
      [sonar:sonar]   at org.apache.tools.ant.Main.runBuild(Main.java:851) [ant.jar:1.9.2]
      [sonar:sonar]   at org.apache.tools.ant.Main.startAnt(Main.java:235) [ant.jar:1.9.2]
      [sonar:sonar]   at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) [ant-launcher.jar:na]
      [sonar:sonar]   at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) [ant-launcher.jar:na]
      [sonar:sonar] 19:09:43.831 WARN  - SQL Error: 0, SQLState: null
      [sonar:sonar] 19:09:43.831 ERROR - Already closed.
  
      BUILD FAILED
      D:\SVN_7_1\buildscripts\sonar.xml:168: org.sonar.runner.impl.RunnerException: Unable to execute Sonar
          at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
          at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
          at java.security.AccessController.doPrivileged(Native Method)
          at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
          at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
          at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
          at org.sonar.runner.api.Runner.execute(Runner.java:100)
          at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:51)
          at org.sonar.ant.SonarTask.execute(SonarTask.java:46)
          at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
          at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:606)
          at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
          at org.apache.tools.ant.Task.perform(Task.java:348)
          at org.apache.tools.ant.Target.execute(Target.java:435)
          at org.apache.tools.ant.Target.performTasks(Target.java:456)
          at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
          at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
          at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
          at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
          at org.apache.tools.ant.Main.runBuild(Main.java:851)
          at org.apache.tools.ant.Main.startAnt(Main.java:235)
          at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
          at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
      Caused by: org.hibernate.exception.GenericJDBCException: Cannot release connection
          at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
          at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:478)
          at org.hibernate.jdbc.ConnectionManager.aggressiveRelease(ConnectionManager.java:429)
          at org.hibernate.jdbc.ConnectionManager.afterTransaction(ConnectionManager.java:316)
          at org.hibernate.jdbc.JDBCContext.afterTransactionCompletion(JDBCContext.java:248)
          at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:158)
          at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
          at org.sonar.jpa.session.JpaDatabaseSession.commit(JpaDatabaseSession.java:83)
          at org.sonar.jpa.session.JpaDatabaseSession.commitAndClose(JpaDatabaseSession.java:69)
          at org.sonar.jpa.session.JpaDatabaseSession.stop(JpaDatabaseSession.java:64)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:606)
          at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
          at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.stop(ReflectionLifecycleStrategy.java:96)
          at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.stop(AbstractInjectionFactory.java:88)
          at org.picocontainer.behaviors.AbstractBehavior.stop(AbstractBehavior.java:179)
          at org.picocontainer.behaviors.Stored$RealComponentLifecycle.stop(Stored.java:141)
          at org.picocontainer.behaviors.Stored.stop(Stored.java:118)
          at org.picocontainer.DefaultPicoContainer.stopAdapters(DefaultPicoContainer.java:1047)
          at org.picocontainer.DefaultPicoContainer.stop(DefaultPicoContainer.java:802)
          at org.sonar.api.platform.ComponentContainer.stopComponents(ComponentContainer.java:123)
          at org.sonar.api.platform.ComponentContainer.stopComponents(ComponentContainer.java:118)
          at org.sonar.batch.bootstrapper.Batch.stop(Batch.java:107)
          at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
          at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:606)
          at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
          ... 24 more
      Caused by: java.sql.SQLException: Already closed.
          at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:114)
          at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:191)
          at org.hibernate.connection.DatasourceConnectionProvider.closeConnection(DatasourceConnectionProvider.java:97)
          at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:474)
          ... 54 more
  
      Total time: 42 minutes 5 seconds
  </code></pre>
  
  <p>I have searched everywhere for a possible solution and so far I haven't been able to find one. If anyone could suggest something I haven't done already then I would really appreciate it.</p>