提交 db1ae558 编写于 作者: dengyihao's avatar dengyihao

[TD-1785]<fix>: taos_close may fail

上级 59068239
...@@ -173,16 +173,12 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread ...@@ -173,16 +173,12 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
static void taosStopTcpThread(SThreadObj* pThreadObj) { static void taosStopTcpThread(SThreadObj* pThreadObj) {
// save thread into local variable and signal thread to stop // save thread into local variable and signal thread to stop
pthread_t thread = pThreadObj->thread; pthread_t thread = pThreadObj->thread;
pThreadObj->stop = true;
if (taosComparePthread(thread, pthread_self())) { if (taosComparePthread(thread, pthread_self())) {
pthread_detach(pthread_self()); pthread_detach(pthread_self());
return; return;
} }
// at this step, pThreadObj has already been released pThreadObj->stop = true;
if (taosCheckPthreadValid(thread)) { pthread_join(thread, NULL);
pthread_join(thread, NULL);
}
} }
void taosStopTcpServer(void *handle) { void taosStopTcpServer(void *handle) {
......
...@@ -301,31 +301,11 @@ static SThreadObj *taosGetTcpThread(SPoolObj *pPool) { ...@@ -301,31 +301,11 @@ static SThreadObj *taosGetTcpThread(SPoolObj *pPool) {
} }
static void taosStopPoolThread(SThreadObj *pThread) { static void taosStopPoolThread(SThreadObj *pThread) {
pThread->stop = true; pthread_t thread = pThread->thread;
if (taosComparePthread(thread, pthread_self())) {
if (pThread->thread == pthread_self()) {
pthread_detach(pthread_self()); pthread_detach(pthread_self());
return; return;
} }
pThread->stop = true;
// save thread ID into a local variable, since pThread is freed when the thread exits
pthread_t thread = pThread->thread;
// signal the thread to stop, try graceful method first,
// and use pthread_cancel when failed
struct epoll_event event = {.events = EPOLLIN};
eventfd_t fd = eventfd(1, 0);
if (fd == -1) {
// failed to create eventfd, call pthread_cancel instead, which may result in data corruption
sError("failed to create eventfd since %s", strerror(errno));
pthread_cancel(pThread->thread);
pThread->stop = true;
} else if (epoll_ctl(pThread->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) {
// failed to call epoll_ctl, call pthread_cancel instead, which may result in data corruption
sError("failed to call epoll_ctl since %s", strerror(errno));
pthread_cancel(pThread->thread);
}
pthread_join(thread, NULL); pthread_join(thread, NULL);
if (fd >= 0) taosClose(fd);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册