提交 bd97d72a 编写于 作者: N nroskill 提交者: LINGuanRen

add guard variable in try-catch stmt to aviod exception not caught

上级 a9f411e7
......@@ -84,9 +84,12 @@ inline int call_with_new_stack(SContext& sctx)
std::function<int()> f = [&]() { \
int ret = OB_SUCCESS; \
try { \
in_try_stmt = true; \
ret = func; \
in_try_stmt = false; \
} catch (OB_BASE_EXCEPTION & except) { \
ret = except.get_errno(); \
in_try_stmt = false; \
} \
return ret; \
}; \
......
......@@ -294,9 +294,12 @@ int CoKThreadTemp<Thread>::start()
Thread* thread = nullptr;
if (OB_FAIL(create_thread(thread, [this, i] {
try {
common::in_try_stmt = true;
this->run(i);
common::in_try_stmt = false;
} catch (common::OB_BASE_EXCEPTION& except) {
UNUSED(except);
common::in_try_stmt = false;
}
}))) {
break;
......
......@@ -221,11 +221,14 @@ void* Thread::__th_start(void* arg)
th->pid_ = getpid();
th->tid_ = static_cast<pid_t>(syscall(__NR_gettid));
try {
in_try_stmt = true;
th->runnable_();
in_try_stmt = false;
} catch (OB_BASE_EXCEPTION& except) {
// we don't catch other exception because we don't know how to handle it
_LOG_ERROR("Exception caught!!! errno = %d, exception info = %s", except.get_errno(), except.what());
ret = OB_ERR_UNEXPECTED;
in_try_stmt = false;
}
}
}
......
......@@ -23,6 +23,7 @@ void right_to_die_or_duty_to_live_c()
namespace oceanbase {
namespace common {
RLOCAL(bool, in_try_stmt);
// To die or to live, it's a problem.
void right_to_die_or_duty_to_live()
......@@ -35,7 +36,13 @@ void right_to_die_or_duty_to_live()
sleep(120);
}
#else
throw OB_EXCEPTION<OB_ERR_UNEXPECTED>();
if (in_try_stmt) {
throw OB_EXCEPTION<OB_ERR_UNEXPECTED>();
} else {
while (true) {
sleep(5);
}
}
#endif
}
......
......@@ -14,11 +14,13 @@
#define SRC_LIB_UTILITY_OB_HANG_FATAL_ERROR_H_
#include <exception>
#include "lib/coro/co_var.h"
namespace oceanbase
{
namespace common
{
extern void right_to_die_or_duty_to_live();
extern RLOCAL(bool, in_try_stmt);
struct OB_BASE_EXCEPTION : public std::exception
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册