未验证 提交 2762bf28 编写于 作者: H Haojun Liao 提交者: GitHub

Merge pull request #20791 from taosdata/origin/2.6

avoid race condition
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
// clang-format off // clang-format off
#include <pthread.h>
#include "os.h" #include "os.h"
#include "tsocket.h" #include "tsocket.h"
#include "tutil.h" #include "tutil.h"
...@@ -644,6 +645,7 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, SOCKET fd) { ...@@ -644,6 +645,7 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, SOCKET fd) {
if (pFdObj == NULL) { if (pFdObj == NULL) {
return NULL; return NULL;
} }
pthread_mutex_lock(&(pThreadObj->mutex));
pFdObj->closedByApp = 0; pFdObj->closedByApp = 0;
pFdObj->fd = fd; pFdObj->fd = fd;
...@@ -654,12 +656,12 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, SOCKET fd) { ...@@ -654,12 +656,12 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, SOCKET fd) {
event.data.ptr = pFdObj; event.data.ptr = pFdObj;
if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) {
tfree(pFdObj); tfree(pFdObj);
pthread_mutex_unlock(&(pThreadObj->mutex));
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return NULL; return NULL;
} }
// notify the data process, add into the FdObj list // notify the data process, add into the FdObj list
pthread_mutex_lock(&(pThreadObj->mutex));
pFdObj->next = pThreadObj->pHead; pFdObj->next = pThreadObj->pHead;
if (pThreadObj->pHead) (pThreadObj->pHead)->prev = pFdObj; if (pThreadObj->pHead) (pThreadObj->pHead)->prev = pFdObj;
pThreadObj->pHead = pFdObj; pThreadObj->pHead = pFdObj;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册