Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-11996

RabbitConsumer could hang when RabbitMQ connection is lost and autoAck=false.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.18.0, 2.19.0, 2.20.0
    • Fix Version/s: 2.19.5, 2.20.3, 2.21.0
    • Component/s: camel-rabbitmq
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      When the connection is lost to a RabbitMQ server and later restored there is the possibility that the RabbitConsumer hangs. The only way around this that I found is to restart my application.

      I have experienced this problem in my testing environment running camel 2.18.3 where my RabbitMQ installation is not stable causing every consumer thread to hang on lock.acquire() .

      The problem has been introduced in version 2.18.0 commit 7ee0977c9f5c327a95122f5b80202dc5dd872e40
      A possible fix could be to include the statement if (!channel.isOpen()) return; in the try-finally block below it.

      JUnit test
      package org.apache.camel.component.rabbitmq;
      
      import org.junit.Test;
      import org.mockito.Mockito;
      
      import com.rabbitmq.client.Channel;
      import com.rabbitmq.client.Connection;
      
      public class RabbitConsumerTest {
        private RabbitMQConsumer consumer = Mockito.mock(RabbitMQConsumer.class);
        private RabbitMQEndpoint endpoint = Mockito.mock(RabbitMQEndpoint.class);
        private Connection conn = Mockito.mock(Connection.class);
        private Channel channel = Mockito.mock(Channel.class);
           
        @Test(timeout=5000)
        public void testHandleDelivery_ShouldNotHangForeverIfChanelWasClosed() throws Exception {  
          Mockito.when(consumer.getEndpoint()).thenReturn(endpoint);  
          Mockito.when(consumer.getConnection()).thenReturn(conn);
          Mockito.when(conn.createChannel()).thenReturn(channel);
          Mockito.when(channel.isOpen()).thenReturn(false).thenReturn(true);
          
          RabbitConsumer rabbitConsumer = new RabbitConsumer(consumer);
          
          rabbitConsumer.handleDelivery(null, null, null, null);
          rabbitConsumer.handleDelivery(null, null, null, null);
          rabbitConsumer.stop();
        }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                davsclaus Claus Ibsen
                Reporter:
                jmongard Joel MongÄrd
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: