add guard variable in try-catch stmt to aviod exception not caught
This commit is contained in:
3
deps/oblib/src/common/ob_smart_call.h
vendored
3
deps/oblib/src/common/ob_smart_call.h
vendored
@ -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; \
|
||||
}; \
|
||||
|
||||
3
deps/oblib/src/lib/coro/co_user_thread.h
vendored
3
deps/oblib/src/lib/coro/co_user_thread.h
vendored
@ -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;
|
||||
|
||||
3
deps/oblib/src/lib/coro/thread.cpp
vendored
3
deps/oblib/src/lib/coro/thread.cpp
vendored
@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user