From 4ecb10d3b1294d03578c28467c0f3759b3496e0b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 7 Mar 2017 12:04:47 +0100 Subject: Resolved potential deadlock When trying to reply to a mail from kube we ran into a deadlock. The initial result callback is called from the main thread, and that can thus directly lead to destruction of the emitter. --- tests/clientapitest.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index da52afb..3955ebd 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -11,6 +11,12 @@ #include "test.h" #include "asyncutils.h" +template +struct Result { + QSharedPointer parent; + bool fetchedAll; +}; + template class TestDummyResourceFacade : public Sink::StoreFacade { @@ -68,7 +74,7 @@ public: auto emitter = resultProvider->emitter(); resultProvider->setFetcher([query, resultProvider, this, ctx](const typename T::Ptr &parent) { - async::run([=] { + async::run>([=] { if (parent) { SinkTraceCtx(ctx) << "Running the fetcher " << parent->identifier(); } else { @@ -90,14 +96,16 @@ public: SinkTraceCtx(ctx) << "Aborting early after " << count << "results."; offset = i + 1; bool fetchedAll = (i + 1 >= results.size()); - resultProvider->initialResultSetComplete(parent, fetchedAll); - return 0; + return Result{parent, fetchedAll}; } } } - resultProvider->initialResultSetComplete(parent, true); - return 0; - }, runAsync).exec(); + return Result{parent, true}; + }, runAsync) + .then([=] (const Result &r) { + resultProvider->initialResultSetComplete(r.parent, r.fetchedAll); + }) + .exec(); }); auto job = KAsync::start([query, resultProvider]() {}); mResultProvider = resultProvider.data(); -- cgit v1.2.3