diff options
author | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2021-11-15 16:49:30 +0200 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2021-11-26 09:21:48 +0200 |
commit | e31fd6c6b68b546771b4d56da36bf3e287448f49 (patch) | |
tree | deeea8f278efcb7cb8acd4b5c2b0671a492d9416 /src/libs/installer | |
parent | 0592a53f197768d0bf08b5740f6612c1a11c18b9 (diff) |
RemoteObject: fix RemoteServer not processing the "Destroy" command
The RemoteObject destructor did not wait that the actual command data
was written to the socket before it was closed.
The incorrect behavior could be noticed with the recently introduced
LibArchiveWrapperPrivate subclass of RemoteObject. Deleting the client
side object would leave the associated RemoteServerConnection thread
owning the wrapped object occasionally in a running state.
Change-Id: I5297fae15d21363227f63b5340946c03cfd03400
Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src/libs/installer')
-rw-r--r-- | src/libs/installer/remoteobject.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/libs/installer/remoteobject.cpp b/src/libs/installer/remoteobject.cpp index 1c521cdf3..f6f0f2bfe 100644 --- a/src/libs/installer/remoteobject.cpp +++ b/src/libs/installer/remoteobject.cpp @@ -30,6 +30,7 @@ #include "protocol.h" #include "remoteclient.h" +#include "globals.h" #include <QCoreApplication> #include <QElapsedTimer> @@ -57,8 +58,20 @@ RemoteObject::~RemoteObject() { if (m_socket) { if (QThread::currentThread() == m_socket->thread()) { - if (m_type != QLatin1String("RemoteClientPrivate")) + if (m_type != QLatin1String("RemoteClientPrivate")) { writeData(QLatin1String(Protocol::Destroy), m_type, dummy, dummy); + while (m_socket->bytesToWrite()) { + // QAbstractSocket::waitForBytesWritten() may fail randomly on Windows, use + // an event loop and the bytesWritten() signal instead as the docs suggest. + QEventLoop loop; + connect(m_socket, &QLocalSocket::bytesWritten, &loop, &QEventLoop::quit); + loop.exec(); + } + if (!m_socket->waitForDisconnected()) { + qCWarning(lcServer) << "Error while disconnecting from remote server:" + << m_socket->error(); + } + } } else { Q_ASSERT_X(false, Q_FUNC_INFO, "Socket running in a different Thread than this object."); } |