Skip to content

Commit f31c71a

Browse files
committed
[daemon] ensure all outstanding futures are done before exit
The daemon object hosts to QFuture and QFutureWatcher objects, which may be still active while the daemon is being destructed. This patch ensures that the destructor call waits for all outstanding futures, and all the raised signals during the lifetime of the futures are delivered to the recipients. Signed-off-by: Mustafa Kemal Gilor <[email protected]>
1 parent 23e6620 commit f31c71a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/daemon/daemon.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,25 @@ mp::Daemon::~Daemon()
14651465
mp::top_catch_all(category, [this] {
14661466
MP_SETTINGS.unregister_handler(instance_mod_handler);
14671467
MP_SETTINGS.unregister_handler(snapshot_mod_handler);
1468+
1469+
/**
1470+
* Wait until all futures are finished, so there will
1471+
* be no outstanding requests left behind. Otherwise, the
1472+
* futures might be interrupted halfway and the actions
1473+
* associated with the futures are not going to be
1474+
* executed.
1475+
*/
1476+
for (auto& [_, watcher] : async_future_watchers)
1477+
{
1478+
watcher->waitForFinished();
1479+
}
1480+
1481+
// waitForFinished() ensures that the futures are finished gracefully
1482+
// but there's a chance that the signals which are queued during their
1483+
// execution haven't got executed yet. So, process all the remaining events
1484+
// in the event loop immediately to ensure that all recipients are notified
1485+
// before the daemon object destructs.
1486+
QCoreApplication::processEvents(QEventLoop::AllEvents);
14681487
});
14691488
}
14701489

0 commit comments

Comments
 (0)