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

This commit is contained in:
nroskill
2021-11-11 14:08:48 +08:00
committed by LINxiansheng
parent a9f411e75c
commit bd97d72a04
5 changed files with 19 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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

View File

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