Wait for finished the canceled task before starting a new one

When Locator::refresh is called, the refresh may be currently
ongoing - in this case we cancel it (and don't wait for it to
be finished) and start a new refresh. So, in theory, refresh
may be running in parallel on more than one non-gui thread.

The consequence may be, that when we then shutdown, we wait
only for the last refresh to finish (we are connected to
m_refreshTask), and doesn't wait for the canceled one to be
finished. This may potentially cause a crash.

We fix it by ensuring, that only one refresh task is run.

Change-Id: I62eeb00375124cdc0ab4651e9280226071d47f3f
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2021-02-11 10:27:31 +01:00
parent 95e7bdfdb7
commit 9ad5cd5f58

View File

@@ -391,6 +391,7 @@ void Locator::refresh(QList<ILocatorFilter *> filters)
if (m_refreshTask.isRunning()) {
m_refreshTask.cancel();
m_refreshTask.waitForFinished();
// this is not ideal because some of the previous filters might have finished, but we
// currently cannot find out which part of a map-reduce has finished
filters = Utils::filteredUnique(m_refreshingFilters + filters);