如何修复 Wildfly 中的“15 秒后无法获取锁”错误

Posted

技术标签:

【中文标题】如何修复 Wildfly 中的“15 秒后无法获取锁”错误【英文标题】:How to fix "Unable to acquire lock after 15 seconds" errors in Wildfly 【发布时间】:2016-06-13 04:37:45 【问题描述】:

我有一个 Web 应用程序 <distributable/>,但也部署到 Wildfly 的独立实例以进行本地开发工作。有时我们对后端的调用可能会停顿几秒钟,这通常会导致如下所示的异常。

鉴于我无法控制长时间运行的后端请求,我该如何解决这个问题?

14:55:04,808 ERROR [org.infinispan.interceptors.InvocationContextInterceptor] (default task-6) ISPN000136: Error executing command LockControlCommand, writing keys []: org.infinispan.util.concurrent.TimeoutException: ISPN000299: Unable to acquire lock after 15 seconds for key LA6Q5r9L1q-VF2tyKE9Pc_bO9yYtzXu8dYt8l-BQ and requestor GlobalTransaction:<null>:37:local. Lock is held by GlobalTransaction:<null>:36:local
    at org.infinispan.util.concurrent.locks.impl.DefaultLockManager$KeyAwareExtendedLockPromise.lock(DefaultLockManager.java:236)
    at org.infinispan.interceptors.locking.AbstractLockingInterceptor.lockAllAndRecord(AbstractLockingInterceptor.java:199)
    at org.infinispan.interceptors.locking.AbstractTxLockingInterceptor.checkPendingAndLockAllKeys(AbstractTxLockingInterceptor.java:199)
    at org.infinispan.interceptors.locking.AbstractTxLockingInterceptor.lockAllOrRegisterBackupLock(AbstractTxLockingInterceptor.java:165)
    at org.infinispan.interceptors.locking.PessimisticLockingInterceptor.visitLockControlCommand(PessimisticLockingInterceptor.java:184)
    at org.infinispan.commands.control.LockControlCommand.acceptVisitor(LockControlCommand.java:110)
    at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:99)
    at org.infinispan.interceptors.TxInterceptor.invokeNextInterceptorAndVerifyTransaction(TxInterceptor.java:157)
    at org.infinispan.interceptors.TxInterceptor.visitLockControlCommand(TxInterceptor.java:215)
    at org.infinispan.commands.control.LockControlCommand.acceptVisitor(LockControlCommand.java:110)
    at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:99)
    at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:107)
    at org.infinispan.interceptors.InvocationContextInterceptor.visitLockControlCommand(InvocationContextInterceptor.java:81)
    at org.infinispan.commands.control.LockControlCommand.acceptVisitor(LockControlCommand.java:110)
    at org.infinispan.interceptors.InterceptorChain.invoke(InterceptorChain.java:336)
    at org.infinispan.cache.impl.CacheImpl.lock(CacheImpl.java:828)
    at org.infinispan.cache.impl.CacheImpl.lock(CacheImpl.java:810)
    at org.infinispan.cache.impl.AbstractDelegatingAdvancedCache.lock(AbstractDelegatingAdvancedCache.java:177)
    at org.wildfly.clustering.web.infinispan.session.InfinispanSessionMetaDataFactory.getValue(InfinispanSessionMetaDataFactory.java:84)
    at org.wildfly.clustering.web.infinispan.session.InfinispanSessionMetaDataFactory.findValue(InfinispanSessionMetaDataFactory.java:69)
    at org.wildfly.clustering.web.infinispan.session.InfinispanSessionMetaDataFactory.findValue(InfinispanSessionMetaDataFactory.java:39)
    at org.wildfly.clustering.web.infinispan.session.InfinispanSessionFactory.findValue(InfinispanSessionFactory.java:61)
    at org.wildfly.clustering.web.infinispan.session.InfinispanSessionFactory.findValue(InfinispanSessionFactory.java:40)
    at org.wildfly.clustering.web.infinispan.session.InfinispanSessionManager.findSession(InfinispanSessionManager.java:234)
    at org.wildfly.clustering.web.undertow.session.DistributableSessionManager.getSession(DistributableSessionManager.java:140)
    at io.undertow.servlet.spec.ServletContextImpl.getSession(ServletContextImpl.java:726)
    at io.undertow.servlet.spec.HttpServletRequestImpl.getSession(HttpServletRequestImpl.java:370)
    at au.com.agic.settings.listener.SessionInvalidatorListener.clearSession(SessionInvalidatorListener.java:57)
    at au.com.agic.settings.listener.SessionInvalidatorListener.requestInitialized(SessionInvalidatorListener.java:52)
    at io.undertow.servlet.core.ApplicationListeners.requestInitialized(ApplicationListeners.java:245)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:283)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

【问题讨论】:

【参考方案1】:

我相信答案是像这样更新 infinispan 配置,这会将锁定超时时间增加到 60 秒。

<cache-container name="web" default-cache="passivation" module="org.wildfly.clustering.web.infinispan">
                <local-cache name="passivation">
                    <locking isolation="REPEATABLE_READ" striping="false" acquire-timeout="60000"/>
                    <transaction mode="BATCH"/>
                    <file-store passivation="true" purge="false"/>
                </local-cache>
                <local-cache name="persistent">
                    <locking isolation="REPEATABLE_READ" striping="false" acquire-timeout="60000"/>
                    <transaction mode="BATCH"/>
                    <file-store passivation="false" purge="false"/>
                </local-cache>
            </cache-container>

【讨论】:

我发现在&lt;transaction mode="batch" /&gt; 元素上设置locking="OPTIMISTIC" 也有帮助。 @Phyxx 您能帮忙解释一下为什么将超时设置为 60 秒可以解决问题吗? 60秒后超时会发生什么? 我认为增加超时是一个短期的解决方案,最终会使问题变得更大 这也许也可以帮助access.redhat.com/solutions/2776221【参考方案2】:

对于一个独立的我有同样的错误

我正在使用这个:

<cache-container name="web" default-cache="dist" module="org.wildfly.clustering.web.infinispan">
    <transport lock-timeout="60000"/>
    <distributed-cache name="dist" mode="ASYNC" l1-lifespan="0" owners="2">  <!-- IN 7.1+ REMOVE mode="..." IF PRESENT -->
        <locking isolation="REPEATABLE_READ"/>                               <!-- REMOVE THIS LINE -->
        <transaction mode="BATCH"/>                                          <!-- REMOVE THIS LINE -->
        <file-store/>
    </distributed-cache>
</cache-container>

但改成:

<cache-container name="web" default-cache="passivation" module="org.wildfly.clustering.web.infinispan">
  <local-cache name="passivation">
      <file-store passivation="true" purge="false"/>
  </local-cache>
  <local-cache name="persistent">
      <file-store passivation="false" purge="false"/>
  </local-cache>
</cache-container>

然后它起作用了。

【讨论】:

以上是关于如何修复 Wildfly 中的“15 秒后无法获取锁”错误的主要内容,如果未能解决你的问题,请参考以下文章

如何将 root(/) 上下文中的 war 文件部署到 Wildfly 9.0.1 版

如何禁用 Wildfly 9.0.2 尝试序列化集群应用程序中的某些类

WildFly 中的字符集编码

覆盖 WildFly 中的日志记录

增加 WildFly 中的 JTA 事务超时限制

如何在 WildFly 10 中将爆炸战争部署为文件夹