From e56d8a3e130e25a7e4153809f1809a6d62b31015 Mon Sep 17 00:00:00 2001 From: TaowerfulMAX Date: Fri, 1 Aug 2025 09:25:31 +0800 Subject: [PATCH 1/4] fix: hdc host server bind target to session failed when session is nullptr. Signed-off-by: TaowerfulMAX --- src/host/server.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/host/server.cpp b/src/host/server.cpp index 3973a7b1..22e76afe 100644 --- a/src/host/server.cpp +++ b/src/host/server.cpp @@ -560,7 +560,9 @@ void HdcServer::UpdateHdiInfo(Hdc::HdcSessionBase::SessionHandShake &handshake, } } hdiNew->version = handshake.version; - AdminDaemonMap(OP_UPDATE, hSession->connectKey, hdiNew); + if (hdiNew->hSession != nullptr) { + AdminDaemonMap(OP_UPDATE, hSession->connectKey, hdiNew); + } } #ifdef HDC_SUPPORT_ENCRYPT_TCP -- Gitee From 9ee7ecbb40f201492777d4f2b9e5551eb37c11be Mon Sep 17 00:00:00 2001 From: TaowerfulMAX Date: Sat, 2 Aug 2025 19:46:15 +0800 Subject: [PATCH 2/4] fix: add inited check flag for AdminDaemonMap concurrent initialization. Signed-off-by: TaowerfulMAX --- src/common/define_plus.h | 1 + src/host/server.cpp | 12 +++++++++--- src/host/server.h | 1 + src/host/server_for_client.cpp | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/common/define_plus.h b/src/common/define_plus.h index f2a29a2d..4d3c37f0 100644 --- a/src/common/define_plus.h +++ b/src/common/define_plus.h @@ -438,6 +438,7 @@ struct HdcDaemonInformation { std::string emgmsg; std::string daemonAuthStatus; std::map daemonFeature; + bool inited; }; using HDaemonInfo = struct HdcDaemonInformation *; diff --git a/src/host/server.cpp b/src/host/server.cpp index 22e76afe..2f710a09 100644 --- a/src/host/server.cpp +++ b/src/host/server.cpp @@ -422,6 +422,7 @@ void HdcServer::NotifyInstanceSessionFree(HSession hSession, bool freeOrClear) if (!freeOrClear) { // step1 // update HdcDaemonInformation diNew = *hdiOld; + diNew.inited = false; diNew.connStatus = STATUS_OFFLINE; diNew.hSession = nullptr; HDaemonInfo hdiNew = &diNew; @@ -528,6 +529,7 @@ void HdcServer::UpdateHdiInfo(Hdc::HdcSessionBase::SessionHandShake &handshake, HdcDaemonInformation diNew = *hdiOld; HDaemonInfo hdiNew = &diNew; // update + hdiNew->inited = false; hdiNew->connStatus = STATUS_CONNECTED; WRITE_LOG(LOG_INFO, "handshake info is : %s", handshake.ToDebugString().c_str()); WRITE_LOG(LOG_INFO, "handshake.buf = %s", handshake.buf.c_str()); @@ -560,9 +562,7 @@ void HdcServer::UpdateHdiInfo(Hdc::HdcSessionBase::SessionHandShake &handshake, } } hdiNew->version = handshake.version; - if (hdiNew->hSession != nullptr) { - AdminDaemonMap(OP_UPDATE, hSession->connectKey, hdiNew); - } + AdminDaemonMap(OP_UPDATE, hSession->connectKey, hdiNew); } #ifdef HDC_SUPPORT_ENCRYPT_TCP @@ -1002,6 +1002,7 @@ int HdcServer::CreateConnect(const string &connectKey, bool isCheck) di.connectKey = connectKey; di.connType = connType; di.connStatus = STATUS_UNKNOW; + di.inited = false; HDaemonInfo pDi = reinterpret_cast(&di); AdminDaemonMap(OP_ADD, "", pDi); AdminDaemonMap(OP_QUERY, connectKey, hdi); @@ -1010,6 +1011,10 @@ int HdcServer::CreateConnect(const string &connectKey, bool isCheck) WRITE_LOG(LOG_FATAL, "Connected return"); return ERR_GENERIC; } + if (hdi->inited == true) { + WRITE_LOG(LOG_FATAL, "Connection is inited"); + return ERR_GENERIC; + } HSession hSession = nullptr; if (connType == CONN_TCP) { hSession = clsTCPClt->ConnectDaemon(connectKey, isCheck); @@ -1044,6 +1049,7 @@ int HdcServer::CreateConnect(const string &connectKey, bool isCheck) if (hdiQuery) { HdcDaemonInformation diNew = *hdiQuery; diNew.hSession = hSession; + diNew.inited = true; HDaemonInfo hdiNew = &diNew; AdminDaemonMap(OP_UPDATE, hdiQuery->connectKey, hdiNew); } diff --git a/src/host/server.h b/src/host/server.h index 5b933837..bdee11cd 100644 --- a/src/host/server.h +++ b/src/host/server.h @@ -55,6 +55,7 @@ public: void *clsServerForClient; std::atomic lastErrorNum; void PrintCmdLogEx(const string &cmdStr); + std::map g_connectKeyMutexes; private: void ClearInstanceResource() override; diff --git a/src/host/server_for_client.cpp b/src/host/server_for_client.cpp index d2461a37..1fbc92e0 100644 --- a/src/host/server_for_client.cpp +++ b/src/host/server_for_client.cpp @@ -385,6 +385,7 @@ void HdcServerForClient::OrderFindTargets(HChannel hChannel) di.connectKey = lst.front(); di.connType = CONN_TCP; di.connStatus = STATUS_READY; + di.inited = false; HDaemonInfo pDi = reinterpret_cast(&di); ptrServer->AdminDaemonMap(OP_ADD, STRING_EMPTY, pDi); lst.pop_front(); @@ -452,6 +453,9 @@ bool HdcServerForClient::NewConnectTry(void *ptrServer, HChannel hChannel, const #ifdef HDC_DEBUG WRITE_LOG(LOG_ALL, "%s %s", __FUNCTION__, Hdc::MaskString(connectKey).c_str()); #endif + HdcServer* serverPtr = reinterpret_cast(ptrServer); + std::mutex& mutex = serverPtr->g_connectKeyMutexes[connectKey]; + std::lock_guard lock(mutex); int childRet = ((HdcServer *)ptrServer)->CreateConnect(connectKey, isCheck); bool ret = false; int connectError = -2; -- Gitee From 3ffafaa333b3e6a71a02024fd8e67233496c396a Mon Sep 17 00:00:00 2001 From: TaowerfulMAX Date: Mon, 4 Aug 2025 23:36:10 +0800 Subject: [PATCH 3/4] fix: add inited check flag for AdminDaemonMap concurrent initialization. Signed-off-by: TaowerfulMAX --- src/host/server.h | 1 - src/host/server_for_client.cpp | 3 --- 2 files changed, 4 deletions(-) diff --git a/src/host/server.h b/src/host/server.h index bdee11cd..5b933837 100644 --- a/src/host/server.h +++ b/src/host/server.h @@ -55,7 +55,6 @@ public: void *clsServerForClient; std::atomic lastErrorNum; void PrintCmdLogEx(const string &cmdStr); - std::map g_connectKeyMutexes; private: void ClearInstanceResource() override; diff --git a/src/host/server_for_client.cpp b/src/host/server_for_client.cpp index 1fbc92e0..5157803a 100644 --- a/src/host/server_for_client.cpp +++ b/src/host/server_for_client.cpp @@ -453,9 +453,6 @@ bool HdcServerForClient::NewConnectTry(void *ptrServer, HChannel hChannel, const #ifdef HDC_DEBUG WRITE_LOG(LOG_ALL, "%s %s", __FUNCTION__, Hdc::MaskString(connectKey).c_str()); #endif - HdcServer* serverPtr = reinterpret_cast(ptrServer); - std::mutex& mutex = serverPtr->g_connectKeyMutexes[connectKey]; - std::lock_guard lock(mutex); int childRet = ((HdcServer *)ptrServer)->CreateConnect(connectKey, isCheck); bool ret = false; int connectError = -2; -- Gitee From a1f21ddeed84e285eb6b016f270f46dea7a626b2 Mon Sep 17 00:00:00 2001 From: TaowerfulMAX Date: Mon, 11 Aug 2025 16:56:59 +0800 Subject: [PATCH 4/4] fix: add inited check flag for AdminDaemonMap concurrent initialization. Signed-off-by: TaowerfulMAX --- src/host/server_for_client.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/host/server_for_client.cpp b/src/host/server_for_client.cpp index 5157803a..1e0ac708 100644 --- a/src/host/server_for_client.cpp +++ b/src/host/server_for_client.cpp @@ -437,6 +437,9 @@ void HdcServerForClient::OrderConnecTargetResult(uv_timer_t *req) bExitRepet = true; sRet = "Connect failed"; thisClass->EchoClient(hChannel, MSG_FAIL, const_cast(sRet.c_str())); + hdi->inited = false; + hdi->connStatus = STATUS_OFFLINE; + ptrServer->AdminDaemonMap(OP_UPDATE, target, hdi); break; } } -- Gitee