Commit 1121db92 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Fix race condition in LoadJob

Currently `extracttest` has random failures when we check properties
with the libarchive plugin.

This happens because there is a race condition between
`LoadJob::onFinished()` (where we read some `LoadJob` members) and
`LoadJob::onNewEntry()` (where we write those members).

`onFinished()` is called when `list()` returns, in `LoadJob::doWork()`.
But that might happen before `onNewEntry()` is called, since they are executed
in two different threads.

This patch puts the `onFinished()` call in the event queue, just like the
single-thread case does (where we emit the `finished` signal from `CliInterface`).

Differential Revision: D3111
parent 5b7544ba
......@@ -260,7 +260,11 @@ void LoadJob::doWork()
bool ret = archiveInterface()->list();
if (!archiveInterface()->waitForFinishedSignal()) {
onFinished(ret);
// onFinished() needs to be called after onNewEntry(), because the former reads members set in the latter.
// So we need to put it in the event queue, just like the single-thread case does by emitting finished().
QTimer::singleShot(0, this, [=]() {
onFinished(ret);
});
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment