Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f2677e2c authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: add hints to waitForService error

If the service is started, it might not be clear why this function
halts. This is a reminder to check to make sure a threadpool is started
and also that it isn't saturated/deadlocked.

Fixes: 146365113
Test: N/A
Change-Id: I4f2d340e99acc5528460062ed309181aa62b9194
parent 6c03e13d
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -326,6 +326,11 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16)

    while(true) {
        {
            // It would be really nice if we could read binder commands on this
            // thread instead of needing a threadpool to be started, but for
            // instance, if we call getAndExecuteCommand, it might be the case
            // that another thread serves the callback, and we never get a
            // command, so we hang indefinitely.
            std::unique_lock<std::mutex> lock(waiter->mMutex);
            using std::literals::chrono_literals::operator""s;
            waiter->mCv.wait_for(lock, 1s, [&] {
@@ -334,6 +339,8 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16)
            if (waiter->mBinder != nullptr) return waiter->mBinder;
        }

        ALOGW("Waited one second for %s (is service started? are binder threads started and available?)", name.c_str());

        // Handle race condition for lazy services. Here is what can happen:
        // - the service dies (not processed by init yet).
        // - sm processes death notification.
@@ -347,8 +354,6 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16)
            return nullptr;
        }
        if (out != nullptr) return out;

        ALOGW("Waited one second for %s", name.c_str());
    }
}