summaryrefslogtreecommitdiff
path: root/libs/binder/RpcState.cpp
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2021-06-22 20:29:21 +0000
committer Steven Moreland <smoreland@google.com> 2021-06-24 18:07:45 +0000
commitb81767912e9101f8522b4393beaf3360dff3ec07 (patch)
tree06d6a785b3ebf1cdbe50eb8e63756e12f0ea9777 /libs/binder/RpcState.cpp
parent936fc19aa0ca565dc0903c577658676ad76575b7 (diff)
libbinder: RPC flake mode
Add mode to make flakes more visible, for debugging. Fixes: 190828148 Test: run w/ binderLibTest and the fuzzer for a bit (no tests fail - some tests can be made to fail by increasing the delay, but this is because some of the tests, namely OnewayStressTest, relies on all operations completing within a certain timeframe) Change-Id: I3b38ff55ffc56410db585fa02e57ac0271da2b5d
Diffstat (limited to 'libs/binder/RpcState.cpp')
-rw-r--r--libs/binder/RpcState.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp
index 53eba5aea6..69ada56ed0 100644
--- a/libs/binder/RpcState.cpp
+++ b/libs/binder/RpcState.cpp
@@ -26,12 +26,28 @@
#include "Debug.h"
#include "RpcWireFormat.h"
+#include <random>
+
#include <inttypes.h>
namespace android {
using base::ScopeGuard;
+#ifdef RPC_FLAKE_PRONE
+void rpcMaybeWaitToFlake() {
+ static std::random_device r;
+ static std::mutex m;
+
+ unsigned num;
+ {
+ std::lock_guard<std::mutex> lock(m);
+ num = r();
+ }
+ if (num % 10 == 0) usleep(num % 1000);
+}
+#endif
+
RpcState::RpcState() {}
RpcState::~RpcState() {}
@@ -226,6 +242,8 @@ status_t RpcState::rpcSend(const base::unique_fd& fd, const sp<RpcSession>& sess
const char* what, const void* data, size_t size) {
LOG_RPC_DETAIL("Sending %s on fd %d: %s", what, fd.get(), hexString(data, size).c_str());
+ MAYBE_WAIT_IN_FLAKE_MODE;
+
if (size > std::numeric_limits<ssize_t>::max()) {
ALOGE("Cannot send %s at size %zu (too big)", what, size);
(void)session->shutdownAndWait(false);