summaryrefslogtreecommitdiff
path: root/libs/binder/RpcState.cpp
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2021-08-05 17:53:16 -0700
committer Steven Moreland <smoreland@google.com> 2021-09-17 18:15:38 +0000
commitae58f43927d1ea51582e0b82f3f2bf2bda83c144 (patch)
treeed8510b4a59dc0f0eb7b073ad7b078059e94ab56 /libs/binder/RpcState.cpp
parentc591b47532d3cc272d5ff80d4632d4b61f2a3b2e (diff)
libbinder: RPC fix 'Die' race
Before this change, what would normally happen is this: 1. we connect to a server and make some calls 2. we make the Die call which returns DEAD_OBJECT 3. we send decStrong on the root binder 4. decStrong on the root binder returns a failure 5. rpcSend calls shutdownAndWait, to terminate the session However, we actually know we should terminate the session at (2) (any failure here indicates a serious problem). This was causing a flake because sometimes (being a send only w/ no read), (4) would return a success. So, we wouldn't shutdown the session. Fixes: 200167417 Test: binderRpcTest --gtest_filter="*Die*" (on Pixel 3, repeatedly) Test: binderRpcTest (on Pixel 3, w/ and w/o this change several times - this does not introduce additional failures, and failures are tracked by b/200173589) Change-Id: I4894c2dd710b8cda59883c91e002b52ad67b1e26
Diffstat (limited to 'libs/binder/RpcState.cpp')
-rw-r--r--libs/binder/RpcState.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp
index 11a083ac11..dcba837a85 100644
--- a/libs/binder/RpcState.cpp
+++ b/libs/binder/RpcState.cpp
@@ -323,6 +323,7 @@ status_t RpcState::rpcRec(const sp<RpcSession::RpcConnection>& connection,
status != OK) {
LOG_RPC_DETAIL("Failed to read %s (%zu bytes) on RpcTransport %p, error: %s", what, size,
connection->rpcTransport.get(), statusToString(status).c_str());
+ (void)session->shutdownAndWait(false);
return status;
}
@@ -531,8 +532,8 @@ status_t RpcState::waitForReply(const sp<RpcSession::RpcConnection>& connection,
const sp<RpcSession>& session, Parcel* reply) {
RpcWireHeader command;
while (true) {
- if (status_t status =
- rpcRec(connection, session, "command header", &command, sizeof(command));
+ if (status_t status = rpcRec(connection, session, "command header (for reply)", &command,
+ sizeof(command));
status != OK)
return status;
@@ -601,7 +602,8 @@ status_t RpcState::getAndExecuteCommand(const sp<RpcSession::RpcConnection>& con
LOG_RPC_DETAIL("getAndExecuteCommand on RpcTransport %p", connection->rpcTransport.get());
RpcWireHeader command;
- if (status_t status = rpcRec(connection, session, "command header", &command, sizeof(command));
+ if (status_t status = rpcRec(connection, session, "command header (for server)", &command,
+ sizeof(command));
status != OK)
return status;