Claus Ibsen created CAMEL-26555:
-----------------------------------

             Summary: camel-core - DefaultShutdownStrategy: a shutdown task 
cancelled on timeout keeps stopping the deferred consumers, on an interrupted 
thread, at the same time as the forced shutdown
                 Key: CAMEL-26555
                 URL: https://issues.apache.org/jira/browse/CAMEL-26555
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: Claus Ibsen
            Assignee: Claus Ibsen
             Fix For: 4.24.0


h3. Problem

When a graceful shutdown times out, {{DefaultShutdownStrategy.doShutdown}} 
cancels its {{ShutdownTask}} with {{future.cancel(true)}} and then, on the 
calling thread, forces the routes to shutdown ({{shutdownRoutesNow}}), or 
aborts, or ignores the remainder routes.

The cancelled task does not stop: its wait loop ends (on the timeout flag, or 
on the interrupt with "Interrupted while waiting during graceful shutdown, will 
force shutdown now."), and it goes on to prepare and stop the deferred 
consumers. So the same consumers are stopped by two threads at the same time, 
and the task does it on a thread whose interrupt flag it has just restored. A 
consumer whose stop waits on something interruptible then fails to stop, for 
example Jetty's {{ManagedSelector.doStop}}:

{noformat}
WARN DefaultShutdownStrategy - Error occurred while shutting down route: ... 
This exception will be ignored.
java.lang.RuntimeException: java.lang.InterruptedException
    at 
org.eclipse.jetty.util.component.ContainerLifeCycle.remove(ContainerLifeCycle.java:730)
    ...
    at 
org.apache.camel.impl.engine.DefaultShutdownStrategy.shutdownNow(DefaultShutdownStrategy.java:434)
    at 
org.apache.camel.impl.engine.DefaultShutdownStrategy$ShutdownTask.run(DefaultShutdownStrategy.java:743)
{noformat}

Which thread reaches a consumer first is a race. In CAMEL-26554 this left a 
camel-jetty port that no longer accepted connections.

h3. Fix

Once the shutdown timed out (or the task was interrupted), the task stops: the 
calling thread owns what happens next (force, abort or ignore), and the 
consumers of a stopped route are stopped by the route stop afterwards anyway.

Found while looking at CAMEL-26554.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to