summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2016-03-16 16:44:36 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-03-22 11:17:07 (GMT)
commit59315e2f10c01451115b66b9f285e26735bbacbf (patch)
tree7832de56ec846d2652ba15bff93f0b1ffc47f463 /src/com/isode
parentf693c8e0fa9c6a051cdf6260f131db3d9355b49f (diff)
downloadstroke-59315e2f10c01451115b66b9f285e26735bbacbf.zip
stroke-59315e2f10c01451115b66b9f285e26735bbacbf.tar.bz2
Try to fix possible race condition in Connector and ProxiedConnection.
As per patch 'Fix possible race condition between Connection and Connectors' (7eec2000d72f8fa597398704121d0b73a84ca284). The issue occurs with ProxiedConnection that started connecting but do not have an external reference anymore. As soon as the handlers of the ProxiedConnection are disconnected from the signals of the connection_ object, the remaining references to a shared ProxiedConnection vanish and the ProxiedConnection is deleted, while it still requires access to its members in ProxiedConnection::handleConnectFinished(). Test-information: Unit tests pass ok. Change-Id: I6c81009262dd51cda17b1b93a15edf968f40e464
Diffstat (limited to 'src/com/isode')
-rw-r--r--src/com/isode/stroke/network/Connector.java9
-rw-r--r--src/com/isode/stroke/network/ProxiedConnection.java10
2 files changed, 16 insertions, 3 deletions
diff --git a/src/com/isode/stroke/network/Connector.java b/src/com/isode/stroke/network/Connector.java
index 6033a89..2823679 100644
--- a/src/com/isode/stroke/network/Connector.java
+++ b/src/com/isode/stroke/network/Connector.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2014, Isode Limited, London, England.
+ * Copyright (c) 2010-2016, Isode Limited, London, England.
* All rights reserved.
*/
/*
@@ -62,6 +62,13 @@ public class Connector {
}
public void stop() {
+ if (currentConnectionConnectFinishedConnection != null) {
+ currentConnectionConnectFinishedConnection.disconnect();
+ currentConnectionConnectFinishedConnection = null;
+ }
+ if (currentConnection != null) {
+ currentConnection.disconnect();
+ }
finish(null);
}
diff --git a/src/com/isode/stroke/network/ProxiedConnection.java b/src/com/isode/stroke/network/ProxiedConnection.java
index 5eac083..69b4b90 100644
--- a/src/com/isode/stroke/network/ProxiedConnection.java
+++ b/src/com/isode/stroke/network/ProxiedConnection.java
@@ -11,6 +11,8 @@
package com.isode.stroke.network;
+import java.util.logging.Logger;
+
import com.isode.stroke.signals.SignalConnection;
import com.isode.stroke.signals.Slot2;
import com.isode.stroke.signals.Slot1;
@@ -30,6 +32,7 @@ public abstract class ProxiedConnection extends Connection {
private SignalConnection onDataReadConnection_;
private SignalConnection onDisconnectedConnection_;
private SignalConnection onConnectFinishedConnection;
+ private Logger logger_ = Logger.getLogger(this.getClass().getName());
public ProxiedConnection(DomainNameResolver resolver, ConnectionFactory connectionFactory, TimerFactory timerFactory, final String proxyHost, int proxyPort) {
this.resolver_ = resolver;
@@ -49,7 +52,7 @@ public abstract class ProxiedConnection extends Connection {
onDisconnectedConnection_.disconnect();
}
if (connected_) {
- System.err.println("Warning: Connection was still established.");
+ logger_.warning("Warning: Connection was still established.");
}
}
finally {
@@ -76,8 +79,11 @@ public abstract class ProxiedConnection extends Connection {
}
public void disconnect() {
+ cancelConnector();
connected_ = false;
- connection_.disconnect();
+ if (connection_ != null) {
+ connection_.disconnect();
+ }
}
public void write(final SafeByteArray data) {