summaryrefslogtreecommitdiff
path: root/libs/binder/RpcSession.cpp
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2021-05-10 23:15:08 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2021-05-10 23:15:08 +0000
commit4fccd098967a1cad0a188672b801bf4e7b515079 (patch)
tree36f7d713d1630b5a7e4cb1df3d7b231c039d599c /libs/binder/RpcSession.cpp
parentc9fb9f924521162fd1959a99d748b6cb35acbb04 (diff)
parentb6a1e7eb34980400bdbabcab756c5a244b1f525b (diff)
Merge changes Ic0719395,Id9f1b639,I00474797,Ide06476a
* changes: libbinder: remove RpcState deadlock debug logs libbinder: RPC avoid abort on too big allocations libbinder: RPC avoid server shutdown crash libbinder: delete dead server objects
Diffstat (limited to 'libs/binder/RpcSession.cpp')
-rw-r--r--libs/binder/RpcSession.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index 09ec20dbf0..f4a3cffa24 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -24,6 +24,7 @@
#include <string_view>
#include <binder/Parcel.h>
+#include <binder/RpcServer.h>
#include <binder/Stability.h>
#include <utils/String8.h>
@@ -142,8 +143,10 @@ void RpcSession::startThread(unique_fd client) {
holdThis->join(unique_fd(fd));
{
std::lock_guard<std::mutex> _l(holdThis->mMutex);
- size_t erased = mThreads.erase(std::this_thread::get_id());
- LOG_ALWAYS_FATAL_IF(erased != 0, "Could not erase thread.");
+ auto it = mThreads.find(std::this_thread::get_id());
+ LOG_ALWAYS_FATAL_IF(it == mThreads.end());
+ it->second.detach();
+ mThreads.erase(it);
}
});
mThreads[thread.get_id()] = std::move(thread);
@@ -168,6 +171,22 @@ void RpcSession::join(unique_fd client) {
"bad state: connection object guaranteed to be in list");
}
+void RpcSession::terminateLocked() {
+ // TODO(b/185167543):
+ // - kindly notify other side of the connection of termination (can't be
+ // locked)
+ // - prevent new client/servers from being added
+ // - stop all threads which are currently reading/writing
+ // - terminate RpcState?
+
+ if (mTerminated) return;
+
+ sp<RpcServer> server = mForServer.promote();
+ if (server) {
+ server->onSessionTerminating(sp<RpcSession>::fromExisting(this));
+ }
+}
+
wp<RpcServer> RpcSession::server() {
return mForServer;
}
@@ -264,6 +283,9 @@ bool RpcSession::removeServerConnection(const sp<RpcConnection>& connection) {
std::lock_guard<std::mutex> _l(mMutex);
if (auto it = std::find(mServers.begin(), mServers.end(), connection); it != mServers.end()) {
mServers.erase(it);
+ if (mServers.size() == 0) {
+ terminateLocked();
+ }
return true;
}
return false;