From c608fba88ed0c69d19551bb64de77994f8d971e3 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Sat, 3 Oct 2020 04:30:02 +0000 Subject: [PATCH] TD-1645 --- src/rpc/src/rpcTcp.c | 7 +++++-- src/rpc/src/rpcUdp.c | 12 +++--------- src/sync/src/taosTcpPool.c | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 46555b3647..06b5d39d61 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -196,7 +196,10 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) { } } - if (taosCheckPthreadValid(pThreadObj->thread) && pThreadObj->pollFd >= 0) pthread_join(pThreadObj->thread, NULL); + if (taosCheckPthreadValid(pThreadObj->thread) && pThreadObj->pollFd >= 0) { + pthread_join(pThreadObj->thread, NULL); + } + if (fd != -1) taosCloseSocket(fd); } @@ -225,7 +228,6 @@ void taosCleanUpTcpServer(void *handle) { for (int i = 0; i < pServerObj->numOfThreads; ++i) { pThreadObj = pServerObj->pThreadObj[i]; taosStopTcpThread(pThreadObj); - pthread_mutex_destroy(&(pThreadObj->mutex)); } tDebug("%s TCP server is cleaned up", pServerObj->label); @@ -526,6 +528,7 @@ static void *taosProcessTcpData(void *param) { taosFreeFdObj(pFdObj); } + pthread_mutex_destroy(&(pThreadObj->mutex)); tDebug("%s TCP thread exits ...", pThreadObj->label); taosTFree(pThreadObj); diff --git a/src/rpc/src/rpcUdp.c b/src/rpc/src/rpcUdp.c index 4fd0318ae6..4ea47582b9 100644 --- a/src/rpc/src/rpcUdp.c +++ b/src/rpc/src/rpcUdp.c @@ -140,18 +140,15 @@ void taosStopUdpConnection(void *handle) { pConn = pSet->udpConn + i; if (pConn->fd >=0) shutdown(pConn->fd, SHUT_RDWR); if (pConn->fd >=0) taosCloseSocket(pConn->fd); - pConn->fd = -1; } for (int i = 0; i < pSet->threads; ++i) { pConn = pSet->udpConn + i; if (taosCheckPthreadValid(pConn->thread)) { - if (taosComparePthread(pConn->thread, pthread_self())) { - pthread_detach(pthread_self()); - } else { - pthread_join(pConn->thread, NULL); - } + pthread_join(pConn->thread, NULL); } + taosTFree(pConn->buffer); + // tTrace("%s UDP thread is closed, index:%d", pConn->label, i); } tDebug("%s UDP is stopped", pSet->label); @@ -233,9 +230,6 @@ static void *taosRecvUdpData(void *param) { (*(pConn->processData))(&recvInfo); } - taosTFree(pConn->buffer); - tDebug("%s UDP recv thread exits", pConn->label); - return NULL; } diff --git a/src/sync/src/taosTcpPool.c b/src/sync/src/taosTcpPool.c index 539cfb64da..6a210a136f 100644 --- a/src/sync/src/taosTcpPool.c +++ b/src/sync/src/taosTcpPool.c @@ -324,5 +324,5 @@ static void taosStopPoolThread(SThreadObj *pThread) { } pthread_join(thread, NULL); - taosClose(fd); + if (fd >= 0) taosClose(fd); } -- GitLab