diff --git a/source/libs/qworker/inc/qwInt.h b/source/libs/qworker/inc/qwInt.h index 729ac474e4720a13a2da8d463820d05db72970f0..0cb1bbe6c3ad8c0c5a82cc82cf324aecce786944 100644 --- a/source/libs/qworker/inc/qwInt.h +++ b/source/libs/qworker/inc/qwInt.h @@ -205,6 +205,7 @@ typedef struct SQWorker { SHashObj *ctxHash; // key: queryId+taskId, value: SQWTaskCtx SMsgCb msgCb; SQWStat stat; + int32_t *destroyed; } SQWorker; typedef struct SQWorkerMgmt { diff --git a/source/libs/qworker/src/qwUtil.c b/source/libs/qworker/src/qwUtil.c index 581eea4a81f90c01333233253d99d8c21f8e1a64..9f1a9a3146b0aeba875d051d731f750779b94e42 100644 --- a/source/libs/qworker/src/qwUtil.c +++ b/source/libs/qworker/src/qwUtil.c @@ -485,6 +485,8 @@ void qwDestroyImpl(void *pMgmt) { } taosHashCleanup(mgmt->schHash); + *mgmt->destroyed = 1; + taosMemoryFree(mgmt); atomic_sub_fetch_32(&gQwMgmt.qwNum, 1); diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 4dcc06b4706b6c85b626bb03877c578e3fe2f8fe..af9399bbdc91e2c8a404dc22218a2b042903ee71 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -1114,10 +1114,17 @@ void qWorkerDestroy(void **qWorkerMgmt) { return; } + int32_t destroyed = 0; SQWorker *mgmt = *qWorkerMgmt; - + mgmt->destroyed = &destroyed; + if (taosRemoveRef(gQwMgmt.qwRef, mgmt->refId)) { qError("remove qw from ref list failed, refId:%" PRIx64, mgmt->refId); + return; + } + + while (0 == destroyed) { + taosMsleep(2); } }