[TD-1785]<fix>: taos_close may fail
This commit is contained in:
parent
590682391b
commit
db1ae55860
|
@ -173,17 +173,13 @@ 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) {
|
||||||
SServerObj *pServerObj = handle;
|
SServerObj *pServerObj = handle;
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue