[TD-1785]<fix>: taos_close may fail
This commit is contained in:
parent
590682391b
commit
db1ae55860
|
@ -173,16 +173,12 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
|
|||
static void taosStopTcpThread(SThreadObj* pThreadObj) {
|
||||
// save thread into local variable and signal thread to stop
|
||||
pthread_t thread = pThreadObj->thread;
|
||||
pThreadObj->stop = true;
|
||||
|
||||
if (taosComparePthread(thread, pthread_self())) {
|
||||
pthread_detach(pthread_self());
|
||||
return;
|
||||
}
|
||||
// at this step, pThreadObj has already been released
|
||||
if (taosCheckPthreadValid(thread)) {
|
||||
pthread_join(thread, NULL);
|
||||
}
|
||||
pThreadObj->stop = true;
|
||||
pthread_join(thread, NULL);
|
||||
}
|
||||
|
||||
void taosStopTcpServer(void *handle) {
|
||||
|
|
|
@ -301,31 +301,11 @@ static SThreadObj *taosGetTcpThread(SPoolObj *pPool) {
|
|||
}
|
||||
|
||||
static void taosStopPoolThread(SThreadObj *pThread) {
|
||||
pThread->stop = true;
|
||||
|
||||
if (pThread->thread == pthread_self()) {
|
||||
pthread_t thread = pThread->thread;
|
||||
if (taosComparePthread(thread, pthread_self())) {
|
||||
pthread_detach(pthread_self());
|
||||
return;
|
||||
}
|
||||
|
||||
// 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->stop = true;
|
||||
pthread_join(thread, NULL);
|
||||
if (fd >= 0) taosClose(fd);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue