[ 
https://issues.apache.org/jira/browse/ARTEMIS-5873?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Timothy A. Bish resolved ARTEMIS-5873.
--------------------------------------
    Fix Version/s: 2.52.0
       Resolution: Fixed

> Potential infinite loop on shutdown
> -----------------------------------
>
>                 Key: ARTEMIS-5873
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-5873
>             Project: Artemis
>          Issue Type: Bug
>          Components: Broker
>    Affects Versions: 2.50.0
>            Reporter: Emmanuel Hugonnet
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 2.52.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> When shutting down the broker the thread pool that holds scheduled tasks is 
> stopped using 
> [ExecutorService.shutdownNow()|https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/concurrent/ExecutorService.html#shutdownNow()].
>  This method will _interrupt_ threads currently executing. 
> If 
> {{org.apache.activemq.artemis.core.server.impl.FileLockNodeManager.MonitorLock}}
>  is running and if it is calling 
> {{org.apache.activemq.artemis.core.server.impl.FileLockNodeManager#getState}} 
> which, in turn, is calling 
> {{java.nio.channels.FileChannel#read(java.nio.ByteBuffer, long)}} then this 
> will result in a {{java.nio.channels.ClosedByInterruptException}} and the 
> {{java.nio.channels.FileChannel}} _will be closed_. A stack-trace like the 
> following will be logged:
> {noformat}
> ERROR [org.apache.activemq.artemis.core.server.impl.FileLockNodeManager] 
> (Thread-2 (activemq-scheduled-default)) 
> java.nio.channels.ClosedByInterruptException: 
> org.apache.activemq.artemis.core.server.NodeManager$NodeManagerException: 
> java.nio.channels.ClosedByInterruptException
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.FileLockNodeManager.getState(FileLockNodeManager.java:375)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.FileLockNodeManager$MonitorLock.run(FileLockNodeManager.java:539)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.ActiveMQScheduledComponent.runForExecutor(ActiveMQScheduledComponent.java:327)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.ActiveMQScheduledComponent.bookedRunForScheduler(ActiveMQScheduledComponent.java:342)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.ActiveMQScheduledComponent.runForScheduler(ActiveMQScheduledComponent.java:353)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.ActiveMQScheduledComponent.lambda$start$0(ActiveMQScheduledComponent.java:180)
>       at 
> java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
>       at 
> java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
>       at 
> java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
>       at 
> java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
>       at 
> java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
>       at 
> [email protected]//org.apache.activemq.artemis.utils.ActiveMQThreadFactory$1.run(ActiveMQThreadFactory.java:120)
> Caused by: java.nio.channels.ClosedByInterruptException
>       at 
> java.base/java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:199)
>       at 
> java.base/sun.nio.ch.FileChannelImpl.endBlocking(FileChannelImpl.java:171)
>       at 
> java.base/sun.nio.ch.FileChannelImpl.readInternal(FileChannelImpl.java:844)
>       at java.base/sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:821)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.FileLockNodeManager.getState(FileLockNodeManager.java:360)
>       ... 11 more{noformat}
> As the broker continues shutting down it will try to use this {{FileChannel}} 
> again to set the status. However, using the aforementioned {{FileChannel}} 
> will result in a {{java.nio.channels.ClosedChannelException}}. This exception 
> will be logged, but it will not be thrown. Instead, 
> {{org.apache.activemq.artemis.core.server.impl.FileLockNodeManager#lock}} 
> will loop forever by default due to {{lockAcquisitionTimeoutNanos}} being set 
> to {{-1}}. Here's an example stack trace logged during this process:
> {noformat}
> WARN  [org.apache.activemq.artemis.core.server.impl.FileLockNodeManager] 
> (ServerService Thread Pool -- 85) Failure when accessing a lock file: 
> java.nio.channels.ClosedChannelException
>       at 
> java.base/sun.nio.ch.FileChannelImpl.ensureOpen(FileChannelImpl.java:159)
>       at 
> java.base/sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1314)
>       at 
> java.base/java.nio.channels.FileChannel.tryLock(FileChannel.java:1191)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.FileLockNodeManager.tryLock(FileLockNodeManager.java:401)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.FileLockNodeManager.lock(FileLockNodeManager.java:421)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.FileLockNodeManager.writeFileLockStatus(FileLockNodeManager.java:336)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.FileLockNodeManager.setPaused(FileLockNodeManager.java:318)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.FileLockNodeManager.pausePrimaryServer(FileLockNodeManager.java:278)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.PrimaryOnlyActivation.close(PrimaryOnlyActivation.java:106)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.stop(ActiveMQServerImpl.java:1488)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.stop(ActiveMQServerImpl.java:1245)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.stop(ActiveMQServerImpl.java:1229)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.stop(ActiveMQServerImpl.java:1062)
>       at 
> [email protected]//org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.stop(ActiveMQServerImpl.java:1056)
>         ...{noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to