From d17d51194f5d8276f2d013733f4ebdd279e02ffd Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Wed, 6 Dec 2023 18:44:55 +0800 Subject: [PATCH] taos_fetch_row cannot be called before the query callback ends. --- source/client/inc/clientInt.h | 1 + source/client/src/clientImpl.c | 2 ++ source/client/src/clientMain.c | 6 ++++++ tests/taosc_test/taoscTest.cpp | 10 ++++++---- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index b4ee619332..a6d5039be7 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -273,6 +273,7 @@ typedef struct SRequestObj { bool killed; bool inRetry; bool isSubReq; + bool inCallback; uint32_t prevCode; // previous error code: todo refactor, add update flag for catalog uint32_t retry; int64_t allocatorRefId; diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index f615111b7f..148cca8dbc 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -2607,7 +2607,9 @@ void taosAsyncFetchImpl(SRequestObj* pRequest, __taos_async_fn_t fp, void* param } void doRequestCallback(SRequestObj* pRequest, int32_t code) { + pRequest->inCallback = true; pRequest->body.queryFp(((SSyncQueryParam *)pRequest->body.interParam)->userParam, pRequest, code); + pRequest->inCallback = false; } int32_t clientParseSql(void* param, const char* dbName, const char* sql, bool parseOnly, const char* effectiveUser, SParseSqlRes* pRes) { diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 1ce7c02dcf..fb36a658e4 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -418,6 +418,12 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { return NULL; } + if(pRequest->inCallback) { + tscError("can not call taos_fetch_row before query callback ends."); + terrno = TSDB_CODE_TSC_INVALID_OPERATION; + return NULL; + } + return doAsyncFetchRows(pRequest, true, true); } else if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) { SMqRspObj *msg = ((SMqRspObj *)res); diff --git a/tests/taosc_test/taoscTest.cpp b/tests/taosc_test/taoscTest.cpp index fbdb152ab4..3f49b11b70 100644 --- a/tests/taosc_test/taoscTest.cpp +++ b/tests/taosc_test/taoscTest.cpp @@ -190,10 +190,12 @@ void queryCallback2(void* param, void* res, int32_t code) { ASSERT_TRUE(param == pUserParam); // After using taos_query_a to query, using taos_fetch_row in the callback will cause blocking. // Reason: schProcessOnCbBegin SCH_LOCK_TASK(pTask) - /* TAOS_ROW row; - while ((row = taos_fetch_row(res))) { - getRecordCounts++; - } */ + TAOS_ROW row; + row = taos_fetch_row(res); + ASSERT_TRUE(row == NULL); + int* errCode = taosGetErrno(); + ASSERT_TRUE(*errCode = TSDB_CODE_TSC_INVALID_OPERATION); + tsem_post(&query_sem); taos_free_result(res); }