From dd3dc7065be453ab3c2ad73aed3ae79c8b162b0d Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Thu, 5 Jun 2008 17:53:32 +0000 Subject: QPID-1116: fixed a race condition in connection/session close, session close now waits for the session to be detached before returning, this guarantees we won't have any active sessions when the connection close is attempted git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@663677 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpidity/transport/ChannelDelegate.java | 3 --- .../java/org/apache/qpidity/transport/Session.java | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'java/common') diff --git a/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java b/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java index 5361613e1e..9470520937 100644 --- a/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java +++ b/java/common/src/main/java/org/apache/qpidity/transport/ChannelDelegate.java @@ -42,9 +42,6 @@ class ChannelDelegate extends MethodDelegate public @Override void sessionDetached(Channel channel, SessionDetached closed) { channel.getSession().closed(); - // XXX: should we remove the channel from the connection? It - // could have an external reference to it. Maybe we need a - // weak hash map in connection. } public @Override void sessionDetach(Channel channel, SessionDetach dtc) diff --git a/java/common/src/main/java/org/apache/qpidity/transport/Session.java b/java/common/src/main/java/org/apache/qpidity/transport/Session.java index a7de66c1a7..c11ef46d36 100644 --- a/java/common/src/main/java/org/apache/qpidity/transport/Session.java +++ b/java/common/src/main/java/org/apache/qpidity/transport/Session.java @@ -459,7 +459,23 @@ public class Session extends Invoker { sessionRequestTimeout(0); sessionDetach(name); - // XXX: channel.close(); + synchronized (commands) + { + long start = System.currentTimeMillis(); + long elapsed = 0; + try + { + while (!closed.get() && elapsed < timeout) + { + commands.wait(timeout - elapsed); + elapsed = System.currentTimeMillis() - start; + } + } + catch (InterruptedException e) + { + throw new RuntimeException(e); + } + } } public void exception(Throwable t) @@ -484,6 +500,9 @@ public class Session extends Invoker } } } + channel.close(); + channel.setSession(null); + channel = null; } public String toString() -- cgit v1.2.1