From a3b042c078fcf0ddc2c4d5d301f6060b1db44eda Mon Sep 17 00:00:00 2001 From: Mario Peng <48949600+Pengrongkun@users.noreply.github.com> Date: Tue, 18 Mar 2025 13:45:20 +0800 Subject: [PATCH] fix: on windows, closing a JDBC PreparedStatement while writing data may cause the JVM to crash. --- source/client/src/clientStmt.c | 20 ++++++++++---------- source/client/src/clientStmt2.c | 16 ++++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 165c7b8bfb..7c9a38679c 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -1630,20 +1630,20 @@ int stmtClose(TAOS_STMT* stmt) { STMT_DLOG_E("start to free stmt"); - pStmt->queue.stopQueue = true; - - (void)taosThreadMutexLock(&pStmt->queue.mutex); - (void)atomic_add_fetch_64(&pStmt->queue.qRemainNum, 1); - (void)taosThreadCondSignal(&(pStmt->queue.waitCond)); - (void)taosThreadMutexUnlock(&pStmt->queue.mutex); - if (pStmt->bindThreadInUse) { + pStmt->queue.stopQueue = true; + + (void)taosThreadMutexLock(&pStmt->queue.mutex); + (void)atomic_add_fetch_64(&pStmt->queue.qRemainNum, 1); + (void)taosThreadCondSignal(&(pStmt->queue.waitCond)); + (void)taosThreadMutexUnlock(&pStmt->queue.mutex); + (void)taosThreadJoin(pStmt->bindThread, NULL); pStmt->bindThreadInUse = false; - } - (void)taosThreadCondDestroy(&pStmt->queue.waitCond); - (void)taosThreadMutexDestroy(&pStmt->queue.mutex); + (void)taosThreadCondDestroy(&pStmt->queue.waitCond); + (void)taosThreadMutexDestroy(&pStmt->queue.mutex); + } STMT_DLOG("stmt %p closed, stbInterlaceMode: %d, statInfo: ctgGetTbMetaNum=>%" PRId64 ", getCacheTbInfo=>%" PRId64 ", parseSqlNum=>%" PRId64 ", pStmt->stat.bindDataNum=>%" PRId64 diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index 75d763ec71..18e3a10c3b 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -1768,18 +1768,18 @@ int stmtClose2(TAOS_STMT2* stmt) { pStmt->queue.stopQueue = true; - (void)taosThreadMutexLock(&pStmt->queue.mutex); - (void)atomic_add_fetch_64(&pStmt->queue.qRemainNum, 1); - (void)taosThreadCondSignal(&(pStmt->queue.waitCond)); - (void)taosThreadMutexUnlock(&pStmt->queue.mutex); - if (pStmt->bindThreadInUse) { + (void)taosThreadMutexLock(&pStmt->queue.mutex); + (void)atomic_add_fetch_64(&pStmt->queue.qRemainNum, 1); + (void)taosThreadCondSignal(&(pStmt->queue.waitCond)); + (void)taosThreadMutexUnlock(&pStmt->queue.mutex); + (void)taosThreadJoin(pStmt->bindThread, NULL); pStmt->bindThreadInUse = false; - } - (void)taosThreadCondDestroy(&pStmt->queue.waitCond); - (void)taosThreadMutexDestroy(&pStmt->queue.mutex); + (void)taosThreadCondDestroy(&pStmt->queue.waitCond); + (void)taosThreadMutexDestroy(&pStmt->queue.mutex); + } if (pStmt->options.asyncExecFn && !pStmt->semWaited) { if (tsem_wait(&pStmt->asyncQuerySem) != 0) {