camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Piero Cangianiello (JIRA)" <>
Subject [jira] [Created] (CAMEL-10229) Race condition when stopping context with autoack=false
Date Tue, 09 Aug 2016 15:48:20 GMT
Piero Cangianiello created CAMEL-10229:

             Summary: Race condition when stopping context with autoack=false
                 Key: CAMEL-10229
             Project: Camel
          Issue Type: Bug
          Components: camel-rabbitmq
    Affects Versions: 2.17.3
            Reporter: Piero Cangianiello

Run the following code and hit enter while one message is in unacked state (see RabbitMQ console):

public static void main(String[] args) throws Exception {
	CamelContext context = new DefaultCamelContext();

	context.addRoutes(new RouteBuilder() {
		public void configure() {
					.setHeader("rabbitmq.ROUTING_KEY", constant("destinationQueue"))
	new BufferedReader(new InputStreamReader(;

you get the following exception:

com.rabbitmq.client.impl.DefaultExceptionHandler: Consumer org.apache.camel.component.rabbitmq.RabbitConsumer@4c57777e
(amq.ctag-dWpQw46flmamv0dM_Fa_Qg) method handleDelivery for channel AMQChannel(amqp://rabbit_user@,1)
threw an exception for channel AMQChannel(amqp://rabbit_user@,1):
com.rabbitmq.client.AlreadyClosedException: channel is already closed due to clean channel
shutdown; protocol method: #method<channel.close>(reply-code=200, reply-text=OK, class-id=0,
	at com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(
	at com.rabbitmq.client.impl.AMQChannel.transmit(
	at com.rabbitmq.client.impl.AMQChannel.transmit(
	at com.rabbitmq.client.impl.ChannelN.basicAck(
	at org.apache.camel.component.rabbitmq.RabbitConsumer.handleDelivery(
	at com.rabbitmq.client.impl.ConsumerDispatcher$
	at com.rabbitmq.client.impl.ConsumerWorkService$
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$

I think that this is caused by a race condition between the main thread that runs channel.close();
immediately after channel.basicCancel(tag); (see org.apache.camel.component.rabbitmq.RabbitConsumer)
without waiting the channel.basicAck(deliveryTag, false); in handleDelivery().

Another bad side effect is that you'll find a duplicate of a message on the destinationQueue.
For example if you have 10 initial messages in sourceQueue and you hit enter while it's processing
the third one, you'll get 7 messages in sourceQueue and 4 messages in destinationQueue.

The correct behaviour should be the following:
1) Stop consumer: channel.basicCancel(tag)
2) Wait if there is a running consumer
3) The consumer acks the previous message
4) Close the channel

This message was sent by Atlassian JIRA

View raw message