Jérôme FOUILLOY created CAMEL-22390:
---------------------------------------

             Summary: Infinite loop on interrupt SedaConsumer
                 Key: CAMEL-22390
                 URL: https://issues.apache.org/jira/browse/CAMEL-22390
             Project: Camel
          Issue Type: Bug
          Components: camel-seda
    Affects Versions: 4.4.0, 4.x
         Environment: Problem detected on Linux, reproduced on Windows 11 
OpenJDK 17.

Bug applicable to all environment.
            Reporter: Jérôme FOUILLOY
         Attachments: Infinite loop interrupt SedaConsumer.zip

We use camel 4.9.0 with Karaf, since update version from version greater than 
4.3 we have infinite loop when my code interrupts an SedaConsumer thread to ask 
the end of processor.

The commit 
https://github.com/apache/camel/commit/1c73ce90679ab0cc5e5bdb36b4e221462af7ef56 
has added interrupt on catch(InterruptedException) in SedaConsumer.

The infinite loop comes from following code :

Exchange exchange = null;
            try {
                // use the end user configured poll timeout
                exchange = queue.poll(pollTimeout, TimeUnit.MILLISECONDS);
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Polled queue {} with timeout {} ms. -> {}", 
ObjectHelper.getIdentityHashCode(queue), pollTimeout,
                            exchange);
                }
                ...
            } catch (InterruptedException e) {
                LOG.debug("Sleep interrupted, are we stopping? {}", 
isStopping() || isStopped());
                Thread.currentThread().interrupt();
            } catch (Exception e) {
                if (exchange != null) {
                    getExceptionHandler().handleException("Error processing 
exchange", exchange, e);
                } else {
                    getExceptionHandler().handleException(e);
                }
            }

My code requests to interrupt the thread SedaConsumer , the queue.poll detects 
interrupted status then it throws an exception, the SedaConsumer catches the 
exception, it marks the camel thread as interrupted, on next loop the camel 
thread calls queue.poll(…) who throws InterruptedException.

=> Infinite loop, the thread consumes about 10% CPU and never terminate, it 
creates memory leak with 100Mo in several seconds on my local computer. The 
DEBUG log spams with message "DEBUG Sleep interrupted, are we stopping? false"

May be my code shouldn't interrupt seda thread, but SedaThread should be never 
create infinite loop on interrupt.

 

I think that main while of SedaConsumer should check an boolean with 
interrupted status set in catch(InterruptedException) instead to call 
interrupt() again.

I have written code to reproduce the problem, see attached zip file with unit 
test.

I have written a patch fix that works fine in my stack, it based on stop the 
while when interrupt is received.



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

Reply via email to