Commit ae060300 authored by Michael Butler's avatar Michael Butler
Browse files

Prevent asynchronous calls from hanging when service crashes

This CL introduces hidl death recipients to prevent asynchronous calls
from hanging when a service dies. The general process is as follows:
(1) Register HIDL death recipient ("DeathHandler") when an interface
    object is constructed.
(2) Register I*Callback object with DeathHandler immediately before an
    asynchronous execution.
(3) Immediately wait for the callback object to be populated with either
    (a) the results of a valid asynchronous execution
    (b) the error code provided by the DeathHandler if the service has
        died
(4) Unregister I*Callback object with DeathHandler after the callback
    object contains a result.
(5) Repeat 2-4 as many times as necessary.
(6) Unregister HIDL death recipient ("DeathHandler") when the HIDL
    interface object is being destroyed.

As an extra convenience and protection, #4 (callback unregistration)
happens automatically when the current scope is exiting via an
RAII-manager "ScopeGuard" object.

Fixes: 118624080
Test: ran "NeuralNetworksTest_static  --gtest_filter=GeneratedTests.add",
killed the sample-all driver, and confirmed (1) that the runtime was not
blocked and (2) that the appropriate log message was recorded. NOTE: this was
facilitated by adding a 10 second sleep in the sample driver for the
asynchronous preparation and asynchronous execution, enabling the service
to be manually killed via "adb shell kill -9 <pid>".

Change-Id: Ie90de41eadfe0d8a1e71f5079962f27ae97852cb
parent 7d91badb
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment