mirror of https://github.com/ByConity/ByConity
Merge 'fix_core_for_bthread_exception' into 'cnch-dev'
fix(clickhousech@m-5284646552): fix bthread_exception infinite recursion See merge request: !24695
This commit is contained in:
parent
0716ad1b4a
commit
ae683e7ed5
|
@ -102,7 +102,10 @@ template<class T, class I>
|
|||
class ThreadLocalManagedBase {
|
||||
public:
|
||||
ThreadLocalManagedBase() noexcept {
|
||||
bthread_key_create(&key, [](void *obj) { delete static_cast<T *>(obj); });
|
||||
bthread_key_create(&key, [](void * obj) {
|
||||
static_cast<T *>(obj)->~T();
|
||||
free(obj);
|
||||
});
|
||||
}
|
||||
|
||||
~ThreadLocalManagedBase() noexcept { bthread_key_delete(key); }
|
||||
|
@ -128,9 +131,3 @@ public:
|
|||
private:
|
||||
bthread_key_t key;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class ThreadLocalManaged : public ThreadLocalManagedBase<T, ThreadLocalManaged<T>> {
|
||||
public:
|
||||
static void *create() { return new T(); }
|
||||
};
|
||||
|
|
|
@ -2,6 +2,15 @@
|
|||
#pragma clang diagnostic ignored "-Wreserved-identifier"
|
||||
#include <common/ThreadLocal.h>
|
||||
|
||||
template<class T>
|
||||
class ThreadLocalManagedUntracked : public ThreadLocalManagedBase<T, ThreadLocalManagedUntracked<T>> {
|
||||
public:
|
||||
static void *create() {
|
||||
void * p = malloc(sizeof(T));
|
||||
return new (p) T();
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
struct __cxa_eh_globals {
|
||||
void * caughtExceptions;
|
||||
|
@ -13,7 +22,7 @@ namespace __cxxabiv1 {
|
|||
|
||||
namespace {
|
||||
__cxa_eh_globals * __globals () {
|
||||
static ThreadLocalManaged<__cxa_eh_globals> eh_globals;
|
||||
static ThreadLocalManagedUntracked<__cxa_eh_globals> eh_globals;
|
||||
return eh_globals.get();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@ void MemoryTracker::allocImpl(Int64 size, bool throw_if_memory_exceeded)
|
|||
#endif
|
||||
|
||||
std::bernoulli_distribution fault(fault_probability);
|
||||
if (unlikely(fault_probability && fault(thread_local_rng)) && memoryTrackerCanThrow(level, true) && throw_if_memory_exceeded)
|
||||
if (unlikely(fault_probability && fault(thread_local_rng)) && throw_if_memory_exceeded && memoryTrackerCanThrow(level, true))
|
||||
{
|
||||
ProfileEvents::increment(ProfileEvents::QueryMemoryLimitExceeded);
|
||||
amount.fetch_sub(size, std::memory_order_relaxed);
|
||||
|
@ -248,7 +248,7 @@ void MemoryTracker::allocImpl(Int64 size, bool throw_if_memory_exceeded)
|
|||
DB::TraceCollector::collect(DB::TraceType::MemorySample, StackTrace(), size);
|
||||
}
|
||||
|
||||
if (unlikely(current_hard_limit && will_be > current_hard_limit) && memoryTrackerCanThrow(level, false) && throw_if_memory_exceeded)
|
||||
if (unlikely(current_hard_limit && will_be > current_hard_limit) && throw_if_memory_exceeded && memoryTrackerCanThrow(level, false))
|
||||
{
|
||||
/// Prevent recursion. Exception::ctor -> std::string -> new[] -> MemoryTracker::alloc
|
||||
BlockerInThread untrack_lock(VariableContext::Global);
|
||||
|
|
Loading…
Reference in New Issue