Improve reliability of SSL connections
authorMichael Marley <michael@michaelmarley.com>
Wed, 11 Dec 2013 21:15:58 +0000 (21:15 +0000)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 13 Jan 2014 23:13:02 +0000 (00:13 +0100)
First, this fixes a bug similar to Bug #1249 except for SSL
connections.  If the TCP connection fails but isn't
actually closed before the SSL handshake is complete,
Quassel will become stuck and never attempt to reconnect.
The solution is to start the ping timeout even earlier,
before the connection is established at all.

Second, this fixes the issue where multiple presses of the
"Disconnect" button and long waits were required to close
certain broken SSL connections (where SSL negotiation was
not yet complete, as above).  The solution is to call
socket.abort() instead of socket.disconnectFromHost(),
which will ensure that the socket is closed immediately.
Additionally, in case that fails for some reason, the
socketCloseTimer is no longer a single-shot timer, so
if the first abort doesn't work, it will keep trying.

(Probably?) fixes bug #1005

src/core/corenetwork.cpp
src/core/corenetwork.h

index e0d4fa6..87f1484 100644 (file)
@@ -44,7 +44,6 @@ CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session)
     _requestedUserModes('-')
 {
     _autoReconnectTimer.setSingleShot(true);
     _requestedUserModes('-')
 {
     _autoReconnectTimer.setSingleShot(true);
-    _socketCloseTimer.setSingleShot(true);
     connect(&_socketCloseTimer, SIGNAL(timeout()), this, SLOT(socketCloseTimeout()));
 
     setPingInterval(networkConfig()->pingInterval());
     connect(&_socketCloseTimer, SIGNAL(timeout()), this, SLOT(socketCloseTimeout()));
 
     setPingInterval(networkConfig()->pingInterval());
@@ -183,6 +182,8 @@ void CoreNetwork::connectToIrc(bool reconnecting)
         socket.setProxy(QNetworkProxy::NoProxy);
     }
 
         socket.setProxy(QNetworkProxy::NoProxy);
     }
 
+    enablePingTimeout();
+
 #ifdef HAVE_SSL
     socket.setProtocol((QSsl::SslProtocol)server.sslVersion);
     if (server.useSsl) {
 #ifdef HAVE_SSL
     socket.setProtocol((QSsl::SslProtocol)server.sslVersion);
     if (server.useSsl) {
@@ -447,8 +448,6 @@ void CoreNetwork::socketInitialized()
 
     emit socketInitialized(identity, localAddress(), localPort(), peerAddress(), peerPort());
 
 
     emit socketInitialized(identity, localAddress(), localPort(), peerAddress(), peerPort());
 
-    enablePingTimeout();
-
     // TokenBucket to avoid sending too much at once
     _messageDelay = 2200;  // this seems to be a safe value (2.2 seconds delay)
     _burstSize = 5;
     // TokenBucket to avoid sending too much at once
     _messageDelay = 2200;  // this seems to be a safe value (2.2 seconds delay)
     _burstSize = 5;
index 5ad27f4..bb7b12a 100644 (file)
@@ -174,7 +174,7 @@ private slots:
     void socketHasData();
     void socketError(QAbstractSocket::SocketError);
     void socketInitialized();
     void socketHasData();
     void socketError(QAbstractSocket::SocketError);
     void socketInitialized();
-    inline void socketCloseTimeout() { socket.disconnectFromHost(); }
+    inline void socketCloseTimeout() { socket.abort(); }
     void socketDisconnected();
     void socketStateChanged(QAbstractSocket::SocketState);
     void networkInitialized();
     void socketDisconnected();
     void socketStateChanged(QAbstractSocket::SocketState);
     void networkInitialized();