diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index bb1fa21aff..192dc4dd71 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -2259,10 +2259,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; @@ -2270,14 +2266,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 6bae063124..53e2fe9b8e 100644 --- a/source/client/test/stmt2Test.cpp +++ b/source/client/test/stmt2Test.cpp @@ -1926,7 +1926,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;