diff --git a/src/dnode/src/dnodeVWrite.c b/src/dnode/src/dnodeVWrite.c index e56bae0d7e84953af493176a585ba3e7060b751b..f2740bf6b810197283926a602db4fc423067e231 100644 --- a/src/dnode/src/dnodeVWrite.c +++ b/src/dnode/src/dnodeVWrite.c @@ -190,6 +190,7 @@ void dnodeFreeVnodeWqueue(void *wqueue) { void dnodeSendRpcVnodeWriteRsp(void *pVnode, void *param, int32_t code) { SWriteMsg *pWrite = (SWriteMsg *)param; + if (pWrite == NULL) return; if (code < 0) pWrite->code = code; int32_t count = atomic_add_fetch_32(&pWrite->processedCount, 1); diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 0b9bbae92eef3942b7a930f30650c412ce2eba46..bc8d360d39509ce9a2fdbe6a9dd883c5c5c99190 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -174,12 +174,15 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) { pThreadObj->stop = true; eventfd_t fd = -1; + // save thread into local variable since pThreadObj is freed when thread exits + pthread_t thread = pThreadObj->thread; + if (taosComparePthread(pThreadObj->thread, pthread_self())) { pthread_detach(pthread_self()); return; } - if (taosCheckPthreadValid(pThreadObj->thread) && pThreadObj->pollFd >= 0) { + if (taosCheckPthreadValid(pThreadObj->thread)) { // signal the thread to stop, try graceful method first, // and use pthread_cancel when failed struct epoll_event event = { .events = EPOLLIN }; @@ -196,8 +199,9 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) { } } - if (taosCheckPthreadValid(pThreadObj->thread) && pThreadObj->pollFd >= 0) { - pthread_join(pThreadObj->thread, NULL); + // at this step, pThreadObj has already been released + if (taosCheckPthreadValid(thread)) { + pthread_join(thread, NULL); } if (fd != -1) taosCloseSocket(fd);