From c7b8910e5407473c53a8ab21054ca4568c281b95 Mon Sep 17 00:00:00 2001 From: JimmyShi22 <417711026@qq.com> Date: Mon, 8 Apr 2024 11:48:34 +0800 Subject: [PATCH] catch exception in fetch txFailed --- bcos-scheduler/src/SchedulerImpl.cpp | 92 ++++++++++++++++------------ 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/bcos-scheduler/src/SchedulerImpl.cpp b/bcos-scheduler/src/SchedulerImpl.cpp index cf16297744..3200d44414 100644 --- a/bcos-scheduler/src/SchedulerImpl.cpp +++ b/bcos-scheduler/src/SchedulerImpl.cpp @@ -401,52 +401,64 @@ void SchedulerImpl::executeBlockInternal(bcos::protocol::Block::Ptr block, bool SCHEDULER_LOG(INFO) << BLOCK_NUMBER(requestBlockNumber) << LOG_BADGE("BlockTrace") << "ExecuteBlock start" << LOG_KV("time(ms)", utcTime() - start); auto startTime = utcTime(); - blockExecutive->asyncExecute( - [this, startTime, requestBlockNumber, callback = std::move(callback), executeLock]( - Error::UniquePtr error, protocol::BlockHeader::Ptr header, bool _sysBlock) { - if (!m_isRunning) - { - executeLock->unlock(); - callback( - BCOS_ERROR_UNIQUE_PTR(SchedulerError::Stopped, "Scheduler is not running"), - nullptr, false); - return; - } + try + { + blockExecutive->asyncExecute( + [this, startTime, requestBlockNumber, callback = std::move(callback), executeLock]( + Error::UniquePtr error, protocol::BlockHeader::Ptr header, bool _sysBlock) { + if (!m_isRunning) + { + executeLock->unlock(); + callback(BCOS_ERROR_UNIQUE_PTR( + SchedulerError::Stopped, "Scheduler is not running"), + nullptr, false); + return; + } - if (error) - { - SCHEDULER_LOG(ERROR) << BLOCK_NUMBER(requestBlockNumber) - << "executeBlock error: " << error->what(); + if (error) { - std::unique_lock blocksLock(m_blocksMutex); - if (!m_blocks->empty() && m_blocks->back()->number() == requestBlockNumber) + SCHEDULER_LOG(ERROR) << BLOCK_NUMBER(requestBlockNumber) + << "executeBlock error: " << error->what(); { - m_blocks->pop_back(); + std::unique_lock blocksLock(m_blocksMutex); + if (!m_blocks->empty() && + m_blocks->back()->number() == requestBlockNumber) + { + m_blocks->pop_back(); + } + blocksLock.unlock(); } - blocksLock.unlock(); + executeLock->unlock(); + callback(BCOS_ERROR_WITH_PREV_PTR( + SchedulerError::UnknownError, "executeBlock error:", *error), + nullptr, _sysBlock); + return; } + auto signature = header->signatureList(); + SCHEDULER_LOG(INFO) + << BLOCK_NUMBER(header->number()) << LOG_BADGE("BlockTrace") + << "ExecuteBlock success" << LOG_KV("hash", header->hash().abridged()) + << LOG_KV("stateRoot", header->stateRoot().hex()) + << LOG_KV("receiptRoot", header->receiptsRoot().hex()) + << LOG_KV("txsRoot", header->txsRoot().abridged()) + << LOG_KV("gasUsed", header->gasUsed()) + << LOG_KV("signatureSize", signature.size()) + << LOG_KV("timeCost", utcTime() - startTime) + << LOG_KV("blockVersion", header->version()); + + m_lastExecuteFinishTime = utcTime(); executeLock->unlock(); - callback(BCOS_ERROR_WITH_PREV_PTR( - SchedulerError::UnknownError, "executeBlock error:", *error), - nullptr, _sysBlock); - return; - } - auto signature = header->signatureList(); - SCHEDULER_LOG(INFO) - << BLOCK_NUMBER(header->number()) << LOG_BADGE("BlockTrace") - << "ExecuteBlock success" << LOG_KV("hash", header->hash().abridged()) - << LOG_KV("stateRoot", header->stateRoot().hex()) - << LOG_KV("receiptRoot", header->receiptsRoot().hex()) - << LOG_KV("txsRoot", header->txsRoot().abridged()) - << LOG_KV("gasUsed", header->gasUsed()) - << LOG_KV("signatureSize", signature.size()) - << LOG_KV("timeCost", utcTime() - startTime) - << LOG_KV("blockVersion", header->version()); - - m_lastExecuteFinishTime = utcTime(); - executeLock->unlock(); - callback(std::move(error), std::move(header), _sysBlock); - }); + callback(std::move(error), std::move(header), _sysBlock); + }); + } + catch (std::exception const& e) + { + executeLock->unlock(); + SCHEDULER_LOG(ERROR) << BLOCK_NUMBER(requestBlockNumber) + << "whenQueueBack asyncExecute exception" + << boost::diagnostic_information(e); + throw e; + } }; // run all handler