diff --git a/src/os/linux/src/linuxPlatform.c b/src/os/linux/src/linuxPlatform.c index 73cccd020aec4f6b59b4fc18f7eca4f93aa28539..782a508b174d87576f454c73dda6478b116207f0 100644 --- a/src/os/linux/src/linuxPlatform.c +++ b/src/os/linux/src/linuxPlatform.c @@ -148,6 +148,10 @@ static void taosDeleteTimer(void *tharg) { timer_delete(*pTimer); } +static pthread_t timerThread; +static timer_t timerId; +static volatile bool stopTimer = false; + void *taosProcessAlarmSignal(void *tharg) { // Block the signal sigset_t sigset; @@ -156,7 +160,6 @@ void *taosProcessAlarmSignal(void *tharg) { sigprocmask(SIG_BLOCK, &sigset, NULL); void (*callback)(int) = tharg; - static timer_t timerId; struct sigevent sevent = {{0}}; #ifdef _ALPINE @@ -187,7 +190,7 @@ void *taosProcessAlarmSignal(void *tharg) { } int signo; - while (1) { + while (!stopTimer) { if (sigwait(&sigset, &signo)) { uError("Failed to wait signal: number %d", signo); continue; @@ -202,7 +205,6 @@ void *taosProcessAlarmSignal(void *tharg) { return NULL; } -static pthread_t timerThread; int taosInitTimer(void (*callback)(int), int ms) { pthread_attr_t tattr; @@ -217,7 +219,7 @@ int taosInitTimer(void (*callback)(int), int ms) { } void taosUninitTimer() { - pthread_cancel(timerThread); + stopTimer = true; pthread_join(timerThread, NULL); } diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 11da145463c6eb43dde0b99120889973e7346355..9a9c659b038a0061c4af3acc5581298800db378d 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -267,8 +267,10 @@ static void httpStopThread(HttpThread* pThread) { struct epoll_event event = { .events = EPOLLIN }; eventfd_t fd = eventfd(1, 0); if (fd == -1) { + httpError("%s, failed to create eventfd, will call pthread_cancel instead, which may result in data corruption: %s", pThread->label, strerror(errno)); pthread_cancel(pThread->thread); } else if (epoll_ctl(pThread->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { + httpError("%s, failed to call epoll_ctl, will call pthread_cancel instead, which may result in data corruption: %s", pThread->label, strerror(errno)); pthread_cancel(pThread->thread); } diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 739b86d7a57ab0027cb3cea4382d93add3db7ab1..a7e00027fb23aeefeb576295d06ab8d3fe62eeaa 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -147,8 +147,10 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) { struct epoll_event event = { .events = EPOLLIN }; eventfd_t fd = eventfd(1, 0); if (fd == -1) { + tError("%s, failed to create eventfd, will call pthread_cancel instead, which may result in data corruption: %s", pThreadObj->label, strerror(errno)); pthread_cancel(pThreadObj->thread); } else if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { + tError("%s, failed to call epoll_ctl, will call pthread_cancel instead, which may result in data corruption: %s", pThreadObj->label, strerror(errno)); pthread_cancel(pThreadObj->thread); }