summaryrefslogtreecommitdiff
path: root/libs/binder/RpcState.cpp
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2021-06-25 19:31:42 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2021-06-25 19:31:42 +0000
commit68aa25522c24fd0193617507bb77341165904a88 (patch)
tree79a146efb9b07c5108423c3c555f9b9c6778e5cc /libs/binder/RpcState.cpp
parentd6afe2eb4bd674c524ae96b4b615671ccdf7f39e (diff)
parentb81767912e9101f8522b4393beaf3360dff3ec07 (diff)
Merge "libbinder: RPC flake mode"
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 32b4b78675..b5eaaa3413 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() {}
@@ -260,6 +276,8 @@ status_t RpcState::rpcSend(const sp<RpcSession::RpcConnection>& connection,
LOG_RPC_DETAIL("Sending %s on fd %d: %s", what, connection->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);