From 76dd5a962a16d7beb367fd9f4ff4c680de3b7dc3 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 9 May 2023 17:19:45 +0800 Subject: [PATCH] fix: fix crash caused by tsdbReaderResume error not handled --- source/dnode/vnode/src/tsdb/tsdbRead.c | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index d0a0ea7947..2fc2b8cdd6 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -4851,7 +4851,11 @@ int32_t tsdbNextDataBlock(STsdbReader* pReader, bool* hasNext) { qTrace("tsdb/read: %p, take read mutex, code: %d", pReader, code); if (pReader->flag == READER_STATUS_SUSPEND) { - tsdbReaderResume(pReader); + code = tsdbReaderResume(pReader); + if (code != TSDB_CODE_SUCCESS) { + tsdbReleaseReader(pReader); + return code; + } } if (pReader->innerReader[0] != NULL && pReader->step == 0) { @@ -5124,11 +5128,17 @@ SSDataBlock* tsdbRetrieveDataBlock(STsdbReader* pReader, SArray* pIdList) { } int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) { + int32_t code = TSDB_CODE_SUCCESS; + qTrace("tsdb/reader-reset: %p, take read mutex", pReader); tsdbAcquireReader(pReader); if (pReader->flag == READER_STATUS_SUSPEND) { - tsdbReaderResume(pReader); + code = tsdbReaderResume(pReader); + if (code != TSDB_CODE_SUCCESS) { + tsdbReleaseReader(pReader); + return code; + } } if (isEmptyQueryTimeWindow(&pReader->window) || pReader->pReadSnap == NULL) { @@ -5163,8 +5173,6 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) { int64_t ts = asc ? pReader->window.skey - 1 : pReader->window.ekey + 1; resetAllDataBlockScanInfo(pStatus->pTableMap, ts, step); - int32_t code = 0; - // no data in files, let's try buffer in memory if (pStatus->fileIter.numOfFiles == 0) { pStatus->loadFromFile = false; @@ -5209,7 +5217,11 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa // find the start data block in file tsdbAcquireReader(pReader); if (pReader->flag == READER_STATUS_SUSPEND) { - tsdbReaderResume(pReader); + code = tsdbReaderResume(pReader); + if (code != TSDB_CODE_SUCCESS) { + tsdbReleaseReader(pReader); + return code; + } } SReaderStatus* pStatus = &pReader->status; @@ -5277,12 +5289,17 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa } int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) { + int32_t code = TSDB_CODE_SUCCESS; int64_t rows = 0; SReaderStatus* pStatus = &pReader->status; tsdbAcquireReader(pReader); if (pReader->flag == READER_STATUS_SUSPEND) { - tsdbReaderResume(pReader); + code = tsdbReaderResume(pReader); + if (code != TSDB_CODE_SUCCESS) { + tsdbReleaseReader(pReader); + return code; + } } int32_t iter = 0; -- GitLab