refcount error for http
This commit is contained in:
parent
61635dc038
commit
052a60452c
|
@ -46,6 +46,8 @@ static void httpDestroyContext(void *data) {
|
||||||
httpReleaseSession(pContext);
|
httpReleaseSession(pContext);
|
||||||
atomic_sub_fetch_32(&pThread->numOfContexts, 1);
|
atomic_sub_fetch_32(&pThread->numOfContexts, 1);
|
||||||
|
|
||||||
|
httpDebug("context:%p, is destroyed, refCount:%d data:%p thread:%s numOfContexts:%d", pContext, pContext->refCount,
|
||||||
|
data, pContext->pThread->label, pContext->pThread->numOfContexts);
|
||||||
pContext->pThread = 0;
|
pContext->pThread = 0;
|
||||||
pContext->state = HTTP_CONTEXT_STATE_CLOSED;
|
pContext->state = HTTP_CONTEXT_STATE_CLOSED;
|
||||||
|
|
||||||
|
@ -53,8 +55,6 @@ static void httpDestroyContext(void *data) {
|
||||||
httpFreeJsonBuf(pContext);
|
httpFreeJsonBuf(pContext);
|
||||||
httpFreeMultiCmds(pContext);
|
httpFreeMultiCmds(pContext);
|
||||||
|
|
||||||
httpDebug("context:%p, is destroyed, refCount:%d data:%p thread:%s numOfContexts:%d", pContext, pContext->refCount,
|
|
||||||
data, pContext->pThread->label, pContext->pThread->numOfContexts);
|
|
||||||
tfree(pContext);
|
tfree(pContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,22 +134,16 @@ HttpContext *httpGetContext(void *ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void httpReleaseContext(HttpContext *pContext) {
|
void httpReleaseContext(HttpContext *pContext) {
|
||||||
// Ensure that the context is valid before release
|
int32_t refCount = atomic_sub_fetch_32(&pContext->refCount, 1);
|
||||||
HttpContext **ppContext = taosCacheAcquireByKey(tsHttpServer.contextCache, &pContext, sizeof(HttpContext *));
|
if (refCount < 0) {
|
||||||
if (ppContext == NULL) {
|
httpError("context:%p, is already released, refCount:%d", pContext, refCount);
|
||||||
httpError("context:%p, is already released", pContext);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t refCount = atomic_sub_fetch_32(&pContext->refCount, 1);
|
HttpContext **ppContext = pContext->ppContext;
|
||||||
assert(refCount >= 0);
|
|
||||||
assert(ppContext == pContext->ppContext);
|
|
||||||
|
|
||||||
httpDebug("context:%p, is released, data:%p refCount:%d", pContext, ppContext, refCount);
|
httpDebug("context:%p, is released, data:%p refCount:%d", pContext, ppContext, refCount);
|
||||||
|
|
||||||
if (tsHttpServer.contextCache != NULL) {
|
if (tsHttpServer.contextCache != NULL) {
|
||||||
// and release context twice
|
|
||||||
taosCacheRelease(tsHttpServer.contextCache, (void **)(&ppContext), false);
|
|
||||||
taosCacheRelease(tsHttpServer.contextCache, (void **)(&ppContext), false);
|
taosCacheRelease(tsHttpServer.contextCache, (void **)(&ppContext), false);
|
||||||
} else {
|
} else {
|
||||||
httpDebug("context:%p, won't be destroyed for cache is already released", pContext);
|
httpDebug("context:%p, won't be destroyed for cache is already released", pContext);
|
||||||
|
|
Loading…
Reference in New Issue