<table><tr><td style="">kfunk created this revision.<br />Herald added a project: KDE PIM.<br />Herald added a subscriber: kde-pim.<br />kfunk requested review of this revision.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D29266">View Revision</a></tr></table><br /><div><strong>REVISION SUMMARY</strong><div><p>On Windows the underlying implementation of QLocalSocket behaves<br />
differently, it seems to trigger the QLocalSocket::readyRead() signal<br />
then anticipated. Prior to this patch this was not handled gracefully.</p>

<p>BEFORE:<br />
Let's have a look at what happens on Windows inside Akonadi's Conneciton<br />
class:</p>

<ul class="remarkup-list">
<li class="remarkup-list-item">Akonadi data sends Hello cmd => 91 bytes</li>
<li class="remarkup-list-item">Akonadi resource receives data</li>
<li class="remarkup-list-item">QLocalSocket::readyReady() signal fires</li>
<li class="remarkup-list-item">Triggers Connection::handleIncomingData via signal-slot connection</li>
<li class="remarkup-list-item">On Windows, QLocalSocket::bytesAvailable() is just 8 bytes</li>
<li class="remarkup-list-item">Only the first 8 bytes are read, into the <tt style="background: #ebebeb; font-size: 13px;">qint64 tag</tt> variable</li>
<li class="remarkup-list-item">Protocol::deserialize(...) is called<ul class="remarkup-list">
<li class="remarkup-list-item">Internally calls waitForData(...) (=> waitForReadyRead()) a few times</li>
</ul></li>
<li class="remarkup-list-item">QLocalSocket::readyRead() signal fires again</li>
<li class="remarkup-list-item">Connection::handleIncomingData re-entered => BUG</li>
</ul>

<p>Problematic end result:</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">[10972] org.kde.pim.akonadicore: tag: -1099511627647
[10972] org.kde.pim.akonadicore: Invalid command, the world is going to end!
[10972] org.kde.pim.akonadicore: State changed: QLocalSocket::ClosingState
[10972] org.kde.pim.akonadicore: State changed: QLocalSocket::UnconnectedState</pre></div>



<h2 class="remarkup-header">> Resource attempts reconnection to server, just to fail again</h2>

<p>afterwards.</p>

<p>AFTER:<br />
The fix is to temporarily disconnect from the readyRead() signal while<br />
attempting to wait for data to deserialize commands. This in order to never<br />
re-enter Connection::handleIncomingData() while doing so.</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R165 Akonadi </div></div></div><br /><div><strong>BRANCH</strong><div><div>master</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D29266">https://phabricator.kde.org/D29266</a></div></div><br /><div><strong>AFFECTED FILES</strong><div><div>src/core/connection.cpp</div></div></div><br /><div><strong>To: </strong>kfunk<br /><strong>Cc: </strong>kde-pim, fbampaloukas, dcaliste, dvasin, rodsevich, winterz, vkrause, mlaurent, knauss, dvratil<br /></div>