From d67392a88b4889247ff60e2773055cc41981ade7 Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Thu, 30 Oct 2014 16:58:52 +0000 Subject: QPID-6202: [Java Broker] Ensure AMQProtocolEngine#closeSession() completes closure even if AMQChannel fails to close cleanly git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1635548 13f79535-47bb-0310-9956-ffa450edef68 --- .../server/protocol/v0_8/AMQProtocolEngine.java | 63 ++++++++++++++++------ 1 file changed, 46 insertions(+), 17 deletions(-) (limited to 'qpid/java') diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java index d3f48fc664..b2b2f904a6 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQProtocolEngine.java @@ -727,17 +727,41 @@ public class AMQProtocolEngine implements ServerProtocolEngine, */ private void closeAllChannels() { - for (AMQChannel channel : getChannels()) - { - channel.close(); - } - synchronized (_channelMap) + try { - _channelMap.clear(); + RuntimeException firstException = null; + for (AMQChannel channel : getChannels()) + { + try + { + channel.close(); + } + catch (RuntimeException re) + { + if (!(re instanceof ConnectionScopedRuntimeException)) + { + _logger.error("Unexpected exception closing channel", re); + } + firstException = re; + } + } + + if (firstException != null) + { + throw firstException; + } } - for (int i = 0; i <= CHANNEL_CACHE_SIZE; i++) + finally { - _cachedChannels[i] = null; + synchronized (_channelMap) + { + _channelMap.clear(); + } + for (int i = 0; i <= CHANNEL_CACHE_SIZE; i++) + { + _cachedChannels[i] = null; + } + } } @@ -767,19 +791,24 @@ public class AMQProtocolEngine implements ServerProtocolEngine, _virtualHost.getConnectionRegistry().deregisterConnection(this); } - closeAllChannels(); - - for (Action task : _taskList) + try { - task.performAction(this); + closeAllChannels(); } - - synchronized(this) + finally { - _closed = true; - notifyAll(); + for (Action task : _taskList) + { + task.performAction(this); + } + + synchronized (this) + { + _closed = true; + notifyAll(); + } + getEventLogger().message(_logSubject, ConnectionMessages.CLOSE()); } - getEventLogger().message(_logSubject, ConnectionMessages.CLOSE()); } } else -- cgit v1.2.1