File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 55#include < deeplake_api/deeplake_api.hpp>
66#include < deeplake_core/deeplake_index_type.hpp>
77
8+ #ifdef __cplusplus
9+ extern " C" {
10+ #endif
11+
12+ #include < storage/ipc.h>
13+
14+ #ifdef __cplusplus
15+ }
16+ #endif
17+
18+ namespace {
19+
20+ // Exit handler that uses _exit() to avoid C++ static destructor crashes.
21+ // PostgreSQL background workers (autovacuum, parallel workers, etc.) can crash
22+ // during normal exit when C++ static objects are destroyed in unpredictable order.
23+ void deeplake_quick_exit (int code, Datum arg)
24+ {
25+ _exit (code);
26+ }
27+
28+ } // anonymous namespace
29+
830namespace pg {
931
1032QueryDesc* query_info::current_query_desc = nullptr ;
@@ -339,6 +361,10 @@ void init_deeplake()
339361 }
340362 initialized = true ;
341363
364+ // Register exit handler first (runs last due to LIFO order) to use _exit()
365+ // and avoid C++ static destructor crashes in background workers.
366+ on_proc_exit (deeplake_quick_exit, 0 );
367+
342368 constexpr int THREAD_POOL_MULTIPLIER = 8 ; // Threads per CPU core for async operations
343369 deeplake_api::initialize (std::make_shared<pg::logger_adapter>(), THREAD_POOL_MULTIPLIER * base::system_report::cpu_cores ());
344370
You can’t perform that action at this time.
0 commit comments