fix: async bind block bug

This commit is contained in:
pengrongkun94@qq.com 2025-03-03 13:51:56 +08:00
parent b741495b5b
commit 4fecfd43ac
2 changed files with 11 additions and 6 deletions

View File

@ -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;

View File

@ -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<std::chrono::seconds>(elapsed_time).count() > 60) {
if (std::chrono::duration_cast<std::chrono::seconds>(elapsed_time).count() > 100) {
FAIL() << "Test[stmt2_async_test] timed out";
t.detach();
break;