Commit ce86c482 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Fixed deadlock. JM-282


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1317 b35dd754-fafc-0310-a699-88a17e54d16e
parent d6bd0c0e
...@@ -187,7 +187,9 @@ public class SocketConnection implements Connection { ...@@ -187,7 +187,9 @@ public class SocketConnection implements Connection {
this.flashClient = flashClient; this.flashClient = flashClient;
} }
public synchronized void close() { public void close() {
boolean wasClosed = false;
synchronized (this) {
if (!isClosed()) { if (!isClosed()) {
try { try {
if (session != null) { if (session != null) {
...@@ -215,6 +217,10 @@ public class SocketConnection implements Connection { ...@@ -215,6 +217,10 @@ public class SocketConnection implements Connection {
Log.error(LocaleUtils.getLocalizedString("admin.error.close") Log.error(LocaleUtils.getLocalizedString("admin.error.close")
+ "\n" + this.toString(), e); + "\n" + this.toString(), e);
} }
wasClosed = true;
}
}
if (wasClosed) {
notifyCloseListeners(); notifyCloseListeners();
} }
} }
...@@ -227,6 +233,7 @@ public class SocketConnection implements Connection { ...@@ -227,6 +233,7 @@ public class SocketConnection implements Connection {
try { try {
// Invoke the interceptors before we send the packet // Invoke the interceptors before we send the packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, false, false); InterceptorManager.getInstance().invokeInterceptors(packet, session, false, false);
boolean errorDelivering = false;
synchronized (writer) { synchronized (writer) {
try { try {
xmlSerializer.write(packet.getElement()); xmlSerializer.write(packet.getElement());
...@@ -236,18 +243,23 @@ public class SocketConnection implements Connection { ...@@ -236,18 +243,23 @@ public class SocketConnection implements Connection {
xmlSerializer.flush(); xmlSerializer.flush();
} }
catch (IOException e) { catch (IOException e) {
Log.warn(LocaleUtils.getLocalizedString("admin.error.close") Log.debug(LocaleUtils.getLocalizedString("admin.error.close")
+ "\n" + this.toString(), e); + "\n" + this.toString(), e);
errorDelivering = true;
}
}
if (errorDelivering) {
close(); close();
// Retry sending the packet again. Most probably if the packet is a // Retry sending the packet again. Most probably if the packet is a
// Message it will be stored offline // Message it will be stored offline
deliverer.deliver(packet); deliverer.deliver(packet);
} }
} else {
// Invoke the interceptors after we have sent the packet // Invoke the interceptors after we have sent the packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, false, true); InterceptorManager.getInstance().invokeInterceptors(packet, session, false, true);
session.incrementServerPacketCount(); session.incrementServerPacketCount();
} }
}
catch (PacketRejectedException e) { catch (PacketRejectedException e) {
// An interceptor rejected the packet so do nothing // An interceptor rejected the packet so do nothing
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment