Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A2BDA200AEE for ; Tue, 24 May 2016 10:28:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A1753160A2D; Tue, 24 May 2016 08:28:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F39C1160A11 for ; Tue, 24 May 2016 10:28:13 +0200 (CEST) Received: (qmail 5103 invoked by uid 500); 24 May 2016 08:28:13 -0000 Mailing-List: contact issues-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list issues@camel.apache.org Received: (qmail 5080 invoked by uid 99); 24 May 2016 08:28:13 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 May 2016 08:28:13 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 0D0402C1F5C for ; Tue, 24 May 2016 08:28:13 +0000 (UTC) Date: Tue, 24 May 2016 08:28:13 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@camel.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CAMEL-9984) RabbitConsumer.stop() doesn't stop underlying AutorecoveringConnection obtained from supplied ConnectionFactory MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 24 May 2016 08:28:14 -0000 [ https://issues.apache.org/jira/browse/CAMEL-9984?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15297889#comment-15297889 ] ASF GitHub Bot commented on CAMEL-9984: --------------------------------------- GitHub user daknin opened a pull request: https://github.com/apache/camel/pull/996 CAMEL-9984: Rabbit MQ connection is not closed when channel has been closed by server. This fixes closing Rabbit MQ connections when the server has already closed the channel / connection. I created an issue at https://issues.apache.org/jira/browse/CAMEL-9984 with full details. You can merge this pull request into a Git repository by running: $ git pull https://github.com/daknin/camel CAMEL-9984 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/camel/pull/996.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #996 ---- commit 09613cb4c3be053195e1c9f68f3a485d0003d24d Author: Darrell King Date: 2016-05-24T08:18:53Z CAMEL-9984: Rabbit MQ connection is not closed when channel has been closed by server. ---- > RabbitConsumer.stop() doesn't stop underlying AutorecoveringConnection obtained from supplied ConnectionFactory > --------------------------------------------------------------------------------------------------------------- > > Key: CAMEL-9984 > URL: https://issues.apache.org/jira/browse/CAMEL-9984 > Project: Camel > Issue Type: Bug > Components: camel-rabbitmq > Affects Versions: 2.17.1 > Reporter: Darrell King > Priority: Minor > Fix For: 2.17.2, 2.18.0 > > > If I have a ConnectionFactory defined as: > {code:borderStyle=solid} > ConnectionFactory connectionFactory = new ConnectionFactory(); > connectionFactory.setAutomaticRecoveryEnabled(true); > connectionFactory.setUsername(username); > connectionFactory.setPassword(password); > {code} > And a Camel route defined like: > {code:borderStyle=solid} > rabbitmq://localhost:5672/MyExchange?connectionFactory=#connectionFactory&exchangeType=direct&queue=MyQueue&routingKey=MyRoutingKey > {code} > Performing these steps: > * Start my application and it connects to Rabbit and consumes messages > * Shutdown the RabbbitMQ server > * Shutdown my Camel application > The application doesn't stop fully because the automatic recovery mechanism has background threads running. It carries on indefinately logging messages like: > {code:borderStyle=solid} > at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106) > at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102) > at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:350) > at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:37) > at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.recoverConnection(AutorecoveringConnection.java:476) > at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.beginAutomaticRecovery(AutorecoveringConnection.java:444) > at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.access$000(AutorecoveringConnection.java:53) > at com.rabbitmq.client.impl.recovery.AutorecoveringConnection$1.shutdownCompleted(AutorecoveringConnection.java:383) > at com.rabbitmq.client.impl.ShutdownNotifierComponent.notifyListeners(ShutdownNotifierComponent.java:75) > at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:578) > {code} > Looking at org.apache.camel.component.rabbitmq.RabbitConsumer.stop() > {code:borderStyle=solid} > public void stop() throws IOException, TimeoutException { > stopping = true; > if (channel == null) { > return; > } > channel.basicCancel(tag); > try { > channel.close(); > } catch (TimeoutException e) { > log.error("Timeout occured"); > throw e; > } > } > {code} > The calls to channel.basicCancel(tag) and channel.close() both throw com.rabbitmq.client.AlreadyClosedException when the server has closed the connection which stops the automatic recovery thread from being halted. Checking whether the channel is open before the calls to channel.basicCancel(tag) and channel.close() seems to fix the issue. > {code:borderStyle=solid} > public void stop() throws IOException, TimeoutException { > stopping = true; > if (channel == null) { > return; > } > if (tag != null && isChannelOpen()) { > channel.basicCancel(tag); > } > try { > if (isChannelOpen()) { > channel.close(); > } > } catch (TimeoutException e) { > log.error("Timeout occured"); > throw e; > } > } > {code} > I'll submit a PR later -- This message was sent by Atlassian JIRA (v6.3.4#6332)