From 4fecfd43ac22c073719a8e892f5c278d8dc49869 Mon Sep 17 00:00:00 2001 From: "pengrongkun94@qq.com" Date: Mon, 3 Mar 2025 13:51:56 +0800 Subject: [PATCH] fix: async bind block bug --- source/client/src/clientMain.c | 15 ++++++++++----- source/client/test/stmt2Test.cpp | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 9a555682e6..431b639298 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -2258,10 +2258,6 @@ int taos_stmt2_bind_param_a(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t c } STscStmt2 *pStmt = (STscStmt2 *)stmt; - if (atomic_load_8((int8_t *)&pStmt->asyncBindParam.asyncBindNum) > 0) { - tscError("async bind param is still working, please try again later"); - return TSDB_CODE_TSC_STMT_API_ERROR; - } ThreadArgs *args = (ThreadArgs *)taosMemoryMalloc(sizeof(ThreadArgs)); args->stmt = stmt; @@ -2269,14 +2265,23 @@ int taos_stmt2_bind_param_a(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t c args->col_idx = col_idx; args->fp = fp; args->param = param; + + (void)taosThreadMutexLock(&(pStmt->asyncBindParam.mutex)); + if (atomic_load_8((int8_t *)&pStmt->asyncBindParam.asyncBindNum) > 0) { + (void)taosThreadMutexUnlock(&(pStmt->asyncBindParam.mutex)); + tscError("async bind param is still working, please try again later"); + return TSDB_CODE_TSC_STMT_API_ERROR; + } (void)atomic_add_fetch_8(&pStmt->asyncBindParam.asyncBindNum, 1); + (void)taosThreadMutexUnlock(&(pStmt->asyncBindParam.mutex)); + int code_s = taosStmt2AsyncBind(stmtAsyncBindThreadFunc, (void *)args); if (code_s != TSDB_CODE_SUCCESS) { (void)taosThreadMutexLock(&(pStmt->asyncBindParam.mutex)); (void)taosThreadCondSignal(&(pStmt->asyncBindParam.waitCond)); (void)atomic_sub_fetch_8(&pStmt->asyncBindParam.asyncBindNum, 1); (void)taosThreadMutexUnlock(&(pStmt->asyncBindParam.mutex)); - // terrno = TAOS_SYSTEM_ERROR(errno); + tscError("async bind failed, code:%d , %s", code_s, tstrerror(code_s)); } return code_s; diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp index 638b964d10..5bc69bb2b0 100644 --- a/source/client/test/stmt2Test.cpp +++ b/source/client/test/stmt2Test.cpp @@ -1882,7 +1882,7 @@ TEST(stmt2Case, async_order) { auto start_time = std::chrono::steady_clock::now(); while (!stop_task) { auto elapsed_time = std::chrono::steady_clock::now() - start_time; - if (std::chrono::duration_cast(elapsed_time).count() > 60) { + if (std::chrono::duration_cast(elapsed_time).count() > 100) { FAIL() << "Test[stmt2_async_test] timed out"; t.detach(); break;