Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2660

Retry when JDBC throws a java.sql.SQLTransactionRollbackException in commitAndClose()

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.0, 2.12.1
    • Component/s: None
    • Labels:
      None

      Description

      Retry when JDBC throws a java.sql.SQLTransactionRollbackException in commitAndClose()

      Hard to reproduce random failure from one of my projects:

      2019-07-19 10:43:34,837 qtp578710141-60 ERROR Unable to write to database <snip>
      	at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.commitAndClose(JdbcDatabaseManager.java:558)
      	at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeThrough(JdbcDatabaseManager.java:875)
      	at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.write(AbstractDatabaseManager.java:264)
      	at org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.append(AbstractDatabaseAppender.java:110)
      	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
      	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
      	at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:543)
      	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:502)
      	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:485)
      	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:460)
      	at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:82)
      	at org.apache.logging.log4j.core.Logger.log(Logger.java:161)
      	at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2190)
      	at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2144)
      	at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2127)
      	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1828)
      	at org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:1282)
      	at com.rs.seagull.httpmonitor.AbstractEventPublisher.publishResponse(AbstractEventPublisher.java:103)
      	at com.rs.seagull.httpmonitor.HttpServletEventPublisher.publishResponse(HttpServletEventPublisher.java:1)
      	at com.rs.seagull.httpmonitor.jetty.PolicyEngineProxyServlet.onProxyResponseFailure(PolicyEngineProxyServlet.java:427)
      	at org.eclipse.jetty.proxy.AsyncMiddleManServlet$ProxyResponseListener.failed(AsyncMiddleManServlet.java:593)
      	at org.eclipse.jetty.util.Callback$Nested.failed(Callback.java:274)
      	at org.eclipse.jetty.util.CountingCallback.failed(CountingCallback.java:88)
      	at org.eclipse.jetty.proxy.AsyncMiddleManServlet$ProxyResponseListener.onComplete(AsyncMiddleManServlet.java:579)
      	at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:196)
      	at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:188)
      	at org.eclipse.jetty.client.HttpExchange.notifyFailureComplete(HttpExchange.java:269)
      	at org.eclipse.jetty.client.HttpExchange.abort(HttpExchange.java:240)
      	at org.eclipse.jetty.client.HttpConversation.abort(HttpConversation.java:149)
      	at org.eclipse.jetty.client.HttpRequest.abort(HttpRequest.java:766)
      	at org.eclipse.jetty.client.HttpDestination.abort(HttpDestination.java:452)
      	at org.eclipse.jetty.client.HttpDestination.failed(HttpDestination.java:234)
      	at org.eclipse.jetty.client.AbstractConnectionPool$1.failed(AbstractConnectionPool.java:140)
      	at org.eclipse.jetty.util.Promise$Wrapper.failed(Promise.java:136)
      	at org.eclipse.jetty.client.HttpClient$1$1.failed(HttpClient.java:608)
      	at org.eclipse.jetty.client.AbstractConnectorHttpClientTransport.connectFailed(AbstractConnectorHttpClientTransport.java:138)
      	at org.eclipse.jetty.client.AbstractConnectorHttpClientTransport$ClientSelectorManager.connectionFailed(AbstractConnectorHttpClientTransport.java:188)
      	at org.eclipse.jetty.io.ManagedSelector$Connect.failed(ManagedSelector.java:811)
      	at org.eclipse.jetty.io.ManagedSelector.processConnect(ManagedSelector.java:243)
      	at org.eclipse.jetty.io.ManagedSelector.access$1500(ManagedSelector.java:61)
      	at org.eclipse.jetty.io.ManagedSelector$SelectorProducer.processSelected(ManagedSelector.java:531)
      	at org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:393)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produceTask(EatWhatYouKill.java:357)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:181)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
      	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:132)
      	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:781)
      	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:917)
      	at java.lang.Thread.run(Thread.java:748)
      Caused by: java.sql.BatchUpdateException: Deadlock found when trying to get lock; try restarting transaction
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      	at com.mysql.cj.util.Util.handleNewInstance(Util.java:192)
      	at com.mysql.cj.util.Util.getInstance(Util.java:167)
      	at com.mysql.cj.util.Util.getInstance(Util.java:174)
      	at com.mysql.cj.jdbc.exceptions.SQLError.createBatchUpdateException(SQLError.java:224)
      	at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchSerially(ClientPreparedStatement.java:849)
      	at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchInternal(ClientPreparedStatement.java:437)
      	at com.mysql.cj.jdbc.StatementImpl.executeBatch(StatementImpl.java:814)
      	at org.apache.commons.dbcp2.DelegatingStatement.executeBatch(DelegatingStatement.java:223)
      	at org.apache.commons.dbcp2.DelegatingStatement.executeBatch(DelegatingStatement.java:223)
      	at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.commitAndClose(JdbcDatabaseManager.java:550)
      	... 50 more
      Caused by: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
      	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:123)
      	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
      	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
      	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:955)
      	at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1094)
      	at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchSerially(ClientPreparedStatement.java:834)
      	... 55 more
      

        Attachments

          Activity

            People

            • Assignee:
              ggregory Gary D. Gregory
              Reporter:
              ggregory Gary D. Gregory
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: