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,34 +187,40 @@ public class SocketConnection implements Connection { ...@@ -187,34 +187,40 @@ public class SocketConnection implements Connection {
this.flashClient = flashClient; this.flashClient = flashClient;
} }
public synchronized void close() { public void close() {
if (!isClosed()) { boolean wasClosed = false;
try { synchronized (this) {
if (session != null) { if (!isClosed()) {
session.setStatus(Session.STATUS_CLOSED); try {
} if (session != null) {
synchronized (writer) { session.setStatus(Session.STATUS_CLOSED);
try { }
writer.write("</stream:stream>"); synchronized (writer) {
if (flashClient) { try {
writer.write('\0'); writer.write("</stream:stream>");
if (flashClient) {
writer.write('\0');
}
xmlSerializer.flush();
} }
xmlSerializer.flush(); catch (IOException e) {}
} }
catch (IOException e) {}
} }
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error.close")
+ "\n" + this.toString(), e);
}
try {
socket.close();
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error.close")
+ "\n" + this.toString(), e);
}
wasClosed = true;
} }
catch (Exception e) { }
Log.error(LocaleUtils.getLocalizedString("admin.error.close") if (wasClosed) {
+ "\n" + this.toString(), e);
}
try {
socket.close();
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error.close")
+ "\n" + this.toString(), e);
}
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,17 +243,22 @@ public class SocketConnection implements Connection { ...@@ -236,17 +243,22 @@ 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);
close(); errorDelivering = true;
// Retry sending the packet again. Most probably if the packet is a
// Message it will be stored offline
deliverer.deliver(packet);
} }
} }
// Invoke the interceptors after we have sent the packet if (errorDelivering) {
InterceptorManager.getInstance().invokeInterceptors(packet, session, false, true); close();
session.incrementServerPacketCount(); // Retry sending the packet again. Most probably if the packet is a
// Message it will be stored offline
deliverer.deliver(packet);
}
else {
// Invoke the interceptors after we have sent the packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, false, true);
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