diff options
author | Tobias Markmann <tm@ayena.de> | 2016-02-25 09:57:59 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2016-02-29 16:54:02 (GMT) |
commit | 7eec2000d72f8fa597398704121d0b73a84ca284 (patch) | |
tree | fd245ceb2b93f5953b386d083e2973fd1e7910ac /Swiften/Network | |
parent | c2b80af83f9ac19fefc21493c5a21ca232662ee2 (diff) | |
download | swift-7eec2000d72f8fa597398704121d0b73a84ca284.zip swift-7eec2000d72f8fa597398704121d0b73a84ca284.tar.bz2 |
Fix possible race condition between Connection and Connectors
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:
All tests pass on OS X 10.11.3. No TSAN reports on Debian 8
in a scenario with randomly connecting/disconnecting Client
instances that use a HTTP proxy.
Change-Id: I4d6d2c85013e066d9ed298aa9b913afc83949e35
Diffstat (limited to 'Swiften/Network')
-rw-r--r-- | Swiften/Network/Connector.cpp | 6 | ||||
-rw-r--r-- | Swiften/Network/ProxiedConnection.cpp | 13 |
2 files changed, 12 insertions, 7 deletions
diff --git a/Swiften/Network/Connector.cpp b/Swiften/Network/Connector.cpp index 5510acb..2775c97 100644 --- a/Swiften/Network/Connector.cpp +++ b/Swiften/Network/Connector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -50,6 +50,10 @@ void Connector::start() { } void Connector::stop() { + if (currentConnection) { + currentConnection->onConnectFinished.disconnect(boost::bind(&Connector::handleConnectionConnectFinished, shared_from_this(), _1)); + currentConnection->disconnect(); + } finish(boost::shared_ptr<Connection>()); } diff --git a/Swiften/Network/ProxiedConnection.cpp b/Swiften/Network/ProxiedConnection.cpp index c44c1f5..69f719d 100644 --- a/Swiften/Network/ProxiedConnection.cpp +++ b/Swiften/Network/ProxiedConnection.cpp @@ -1,17 +1,15 @@ /* - * Copyright (c) 2012-2015 Isode Limited. + * Copyright (c) 2012-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ - #include <Swiften/Network/ProxiedConnection.h> -#include <iostream> - #include <boost/bind.hpp> #include <Swiften/Base/ByteArray.h> +#include <Swiften/Base/Log.h> #include <Swiften/Network/ConnectionFactory.h> #include <Swiften/Network/HostAddressPort.h> @@ -39,7 +37,7 @@ ProxiedConnection::~ProxiedConnection() { connection_->onDisconnected.disconnect(boost::bind(&ProxiedConnection::handleDisconnected, shared_from_this(), _1)); } if (connected_) { - std::cerr << "Warning: Connection was still established." << std::endl; + SWIFT_LOG(warning) << "Connection was still established." << std::endl; } } @@ -65,8 +63,11 @@ void ProxiedConnection::listen() { } void ProxiedConnection::disconnect() { + cancelConnector(); connected_ = false; - connection_->disconnect(); + if (connection_) { + connection_->disconnect(); + } } void ProxiedConnection::handleDisconnected(const boost::optional<Error>& error) { |