userver-framework / userver

Production-ready C++ Asynchronous Framework with rich functionality
https://userver.tech
Apache License 2.0
2.36k stars 272 forks source link

BUG: MacOS arm64 #564

Open root-kidik opened 4 months ago

root-kidik commented 4 months ago

OS: MacOS arm64 Compiler: AppleClang

Install userver

cmake -S./ -B./build_debug \
    -DCMAKE_BUILD_TYPE=Debug \
    -DUSERVER_INSTALL=ON \
    -DUSERVER_SANITIZE="ub addr" \
    -DUSERVER_FEATURE_GRPC=ON  \
    -DUSERVER_FEATURE_POSTGRESQL=ON \
    -DUSERVER_PG_LIBRARY_DIR=$(pg_config --libdir) -DUSERVER_PG_INCLUDE_DIR=$(pg_config --includedir) \
    -DUSERVER_PG_SERVER_LIBRARY_DIR=$(pg_config --pkglibdir) -DUSERVER_PG_SERVER_INCLUDE_DIR=$(pg_config --includedir-server) \
    -GNinja
cmake --build build_debug/
sudo cmake --install build_debug/

Run pg_grpc_service_template

lldb ./pg_grpc_service_template                                                                                                                                                 ─╯
(lldb) target create "./pg_grpc_service_template"
Current executable set to '/Users/nikitatabakaev/Downloads/pg_grpc_service_template/build_debug/pg_grpc_service_template' (arm64).
(lldb) r -c ../configs/static_config.yaml --config_vars ../configs/config_vars.yaml
Process 13108 launched: '/Users/nikitatabakaev/Downloads/pg_grpc_service_template/build_debug/pg_grpc_service_template' (arm64)
tskv    timestamp=2024-05-04T16:26:28.085071    level=INFO  module=ParseManagerConfigAndSetupLogging ( userver/core/src/components/run.cpp:177 )    task_id=0   thread_id=0x00000001EE9B3AC0    text=Parsed configs from file '../configs/static_config.yaml' using config_vars from cmdline in file '../configs/config_vars.yaml'
tskv    timestamp=2024-05-04T16:26:28.085340    level=WARNING   module=HandleJemallocSettings ( userver/core/src/components/run.cpp:75 )    task_id=0   thread_id=0x00000001EE9B3AC0    text=Failed to set max_background_threads to 1
tskv    timestamp=2024-05-04T16:26:28.089308    level=INFO  module=PreheatStacktraceCollector ( userver/core/src/components/run.cpp:100 )   task_id=0   thread_id=0x00000001EE9B3AC0    text=Initialized stacktrace collector within 3ms
Process 13108 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x102520040)
    frame #0: 0x0000000186cda078 libsystem_platform.dylib`getcontext + 60
libsystem_platform.dylib`getcontext:
->  0x186cda078 <+60>: stp    x10, x12, [x0, #0xf8]
    0x186cda07c <+64>: str    x11, [x0, #0x108]
    0x186cda080 <+68>: str    w13, [x0, #0x11c]
    0x186cda084 <+72>: stp    x19, x20, [x0, #0xa8]
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x102520040)
  * frame #0: 0x0000000186cda078 libsystem_platform.dylib`getcontext + 60
    frame #1: 0x00000001005440d4 pg_grpc_service_template`boost::context::detail::fiber_activation_record* boost::context::detail::create_fiber2<boost::context::fiber, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, boost::coroutines2::detail::push_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>::control_block::control_block<boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&)>(boost::context::preallocated, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&))::'lambda'(boost::context::fiber&&)>(palloc=preallocated @ 0x000000016fdfd840, salloc=0x000000013b80fe38, fn=0x000000016fdfd910) at fiber_ucontext.hpp:373:10
    frame #2: 0x000000010054403c pg_grpc_service_template`boost::context::fiber::fiber<boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, boost::coroutines2::detail::push_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>::control_block::control_block<boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&)>(boost::context::preallocated, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&))::'lambda'(boost::context::fiber&&)>(this=0x000000010251ffc0, (null)=allocator_arg_t @ 0x000000016fdfd88f, palloc=preallocated @ 0x000000016fdfd920, salloc=0x000000013b80fe38, fn=0x000000016fdfd910) at fiber_ucontext.hpp:453:15
    frame #3: 0x0000000100543fe4 pg_grpc_service_template`boost::context::fiber::fiber<boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, boost::coroutines2::detail::push_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>::control_block::control_block<boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&)>(boost::context::preallocated, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&))::'lambda'(boost::context::fiber&&)>(this=0x000000010251ffc0, (null)=allocator_arg_t @ 0x000000016fdfd8cf, palloc=preallocated @ 0x000000016fdfd920, salloc=0x000000013b80fe38, fn=0x000000016fdfd910) at fiber_ucontext.hpp:454:90
    frame #4: 0x0000000100543f30 pg_grpc_service_template`boost::coroutines2::detail::push_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>::control_block::control_block<boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&)>(this=0x000000010251ffc0, palloc=preallocated @ 0x000000016fdfd9e8, salloc=0x000000013b80fe38, fn=0x000000013b80fe30) at push_control_block_cc.ipp:79:5
    frame #5: 0x0000000100543e3c pg_grpc_service_template`boost::coroutines2::detail::push_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>::control_block::control_block<boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&)>(this=0x000000010251ffc0, palloc=preallocated @ 0x000000016fdfd9e8, salloc=0x000000013b80fe38, fn=0x000000013b80fe30) at push_control_block_cc.ipp:110:14
    frame #6: 0x0000000100543c50 pg_grpc_service_template`boost::coroutines2::detail::push_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>::control_block* boost::coroutines2::detail::create_control_block<boost::coroutines2::detail::push_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>::control_block, boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&)>(salloc=0x000000013b80fe38, fn=0x000000013b80fe30) at create_control_block.ipp:50:22
    frame #7: 0x0000000100543b48 pg_grpc_service_template`boost::coroutines2::detail::push_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>::push_coroutine<boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&)>(this=0x000000016fdfdcd0, salloc=0x000000013b80fe38, fn=0x000000013b80fe30) at push_coroutine.ipp:47:10
    frame #8: 0x0000000100543acc pg_grpc_service_template`boost::coroutines2::detail::push_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>::push_coroutine<boost::context::basic_protected_fixedsize_stack<boost::context::stack_traits>&, void (* const&)(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&)>(this=0x000000016fdfdcd0, salloc=0x000000013b80fe38, fn=0x000000013b80fe30) at push_coroutine.ipp:47:118
    frame #9: 0x0000000100542938 pg_grpc_service_template`userver::v2_0_rc::engine::coro::Pool<userver::v2_0_rc::engine::impl::TaskContext>::CreateCoroutine(this=0x000000013b80fe18, quiet=true) at pool.hpp:163:15
    frame #10: 0x000000010054975c pg_grpc_service_template`userver::v2_0_rc::engine::coro::Pool<userver::v2_0_rc::engine::impl::TaskContext>::Pool(this=0x000000013b80fe18, config=(initial_size = 1000, max_size = 4000, stack_size = 262144), executor=(pg_grpc_service_template`userver::v2_0_rc::engine::impl::TaskContext::CoroFunc(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&) at task_context.cpp:484)) at pool.hpp:104:44
    frame #11: 0x000000010054950c pg_grpc_service_template`userver::v2_0_rc::engine::coro::Pool<userver::v2_0_rc::engine::impl::TaskContext>::Pool(this=0x000000013b80fe18, config=(initial_size = 1000, max_size = 4000, stack_size = 262144), executor=(pg_grpc_service_template`userver::v2_0_rc::engine::impl::TaskContext::CoroFunc(boost::coroutines2::detail::pull_coroutine<userver::v2_0_rc::engine::impl::TaskContext*>&) at task_context.cpp:484)) at pool.hpp:100:32
    frame #12: 0x00000001005493c8 pg_grpc_service_template`userver::v2_0_rc::engine::impl::TaskProcessorPools::TaskProcessorPools(this=0x000000013b80fe18, coro_pool_config=(initial_size = 1000, max_size = 4000, stack_size = 262144), ev_pool_config=ThreadPoolConfig @ 0x000000016fdfde80) at task_processor_pools.cpp:15:7
    frame #13: 0x0000000100549574 pg_grpc_service_template`userver::v2_0_rc::engine::impl::TaskProcessorPools::TaskProcessorPools(this=0x000000013b80fe18, coro_pool_config=(initial_size = 1000, max_size = 4000, stack_size = 262144), ev_pool_config=ThreadPoolConfig @ 0x000000016fdfde80) at task_processor_pools.cpp:17:61
    frame #14: 0x00000001003f8f68 pg_grpc_service_template`std::__1::__shared_ptr_emplace<userver::v2_0_rc::engine::impl::TaskProcessorPools, std::__1::allocator<userver::v2_0_rc::engine::impl::TaskProcessorPools>>::__shared_ptr_emplace[abi:ue170006]<userver::v2_0_rc::engine::coro::PoolConfig const&, userver::v2_0_rc::engine::ev::ThreadPoolConfig const&>(this=0x000000013b80fe00, __a=allocator<userver::v2_0_rc::engine::impl::TaskProcessorPools> @ 0x000000016fdfdeff, __args=0x000060000160d450, __args=0x000060000160d468) at shared_ptr.h:303:37
    frame #15: 0x00000001003f8c10 pg_grpc_service_template`std::__1::__shared_ptr_emplace<userver::v2_0_rc::engine::impl::TaskProcessorPools, std::__1::allocator<userver::v2_0_rc::engine::impl::TaskProcessorPools>>::__shared_ptr_emplace[abi:ue170006]<userver::v2_0_rc::engine::coro::PoolConfig const&, userver::v2_0_rc::engine::ev::ThreadPoolConfig const&>(this=0x000000013b80fe00, __a=allocator<userver::v2_0_rc::engine::impl::TaskProcessorPools> @ 0x000000016fdfdf3f, __args=0x000060000160d450, __args=0x000060000160d468) at shared_ptr.h:292:5
    frame #16: 0x00000001003f8b10 pg_grpc_service_template`std::__1::shared_ptr<userver::v2_0_rc::engine::impl::TaskProcessorPools> std::__1::allocate_shared[abi:ue170006]<userver::v2_0_rc::engine::impl::TaskProcessorPools, std::__1::allocator<userver::v2_0_rc::engine::impl::TaskProcessorPools>, userver::v2_0_rc::engine::coro::PoolConfig const&, userver::v2_0_rc::engine::ev::ThreadPoolConfig const&, void>(__a=0x000000016fdfdfe7, __args=0x000060000160d450, __args=0x000060000160d468) at shared_ptr.h:1023:55
    frame #17: 0x00000001003ed97c pg_grpc_service_template`std::__1::shared_ptr<userver::v2_0_rc::engine::impl::TaskProcessorPools> std::__1::make_shared[abi:ue170006]<userver::v2_0_rc::engine::impl::TaskProcessorPools, userver::v2_0_rc::engine::coro::PoolConfig const&, userver::v2_0_rc::engine::ev::ThreadPoolConfig const&, void>(__args=0x000060000160d450, __args=0x000060000160d468) at shared_ptr.h:1032:12
    frame #18: 0x00000001003ed15c pg_grpc_service_template`userver::v2_0_rc::components::Manager::Manager(this=0x000000016fdfe818, config=nullptr, component_list=0x000000016fdff098) at manager.cpp:137:11
    frame #19: 0x00000001003ee300 pg_grpc_service_template`userver::v2_0_rc::components::Manager::Manager(this=0x000000016fdfe818, config=nullptr, component_list=0x000000016fdff098) at manager.cpp:139:53
    frame #20: 0x0000000100435e1c pg_grpc_service_template`void std::__1::__optional_storage_base<userver::v2_0_rc::components::Manager, false>::__construct[abi:ue170006]<std::__1::unique_ptr<userver::v2_0_rc::components::ManagerConfig, std::__1::default_delete<userver::v2_0_rc::components::ManagerConfig>>, userver::v2_0_rc::components::ComponentList const&>(this=0x000000016fdfe818, __args=nullptr, __args=0x000000016fdff098) at optional:420:55
    frame #21: 0x0000000100434824 pg_grpc_service_template`userver::v2_0_rc::components::Manager& std::__1::optional<userver::v2_0_rc::components::Manager>::emplace[abi:ue170006]<std::__1::unique_ptr<userver::v2_0_rc::components::ManagerConfig, std::__1::default_delete<userver::v2_0_rc::components::ManagerConfig>>, userver::v2_0_rc::components::ComponentList const&, void>(this= Has Value=false , __args=nullptr, __args=0x000000016fdff098) at optional:950:15
    frame #22: 0x00000001004329c4 pg_grpc_service_template`userver::v2_0_rc::components::(anonymous namespace)::DoRun(config= Active Type = std::string , config_vars_path= Has Value=true , config_vars_override_path= Has Value=false , component_list=0x000000016fdff098, run_mode=kNormal) at run.cpp:214:13
    frame #23: 0x000000010043280c pg_grpc_service_template`userver::v2_0_rc::components::Run(config_path="../configs/static_config.yaml", config_vars_path= Has Value=true , config_vars_override_path= Has Value=false , component_list=0x000000016fdff098) at run.cpp:251:3
    frame #24: 0x00000001006fb3e0 pg_grpc_service_template`userver::v2_0_rc::utils::DaemonMain(argc=5, argv=0x000000016fdff318, components_list=0x000000016fdff098) at daemon_run.cpp:75:5
    frame #25: 0x000000010000adf4 pg_grpc_service_template`main(argc=5, argv=0x000000016fdff318) at main.cpp:28:10
    frame #26: 0x000000018691e0e0 dyld`start + 2360
(lldb)
levongh commented 1 month ago

This issue most probably comes from the MacOS specifics for fork() function call from file ./core/src/engine/subprocess/process_starter.cpp in ProcessStarter::Exec there is an explicit fork() call which is leading to such problem.

there either need to switch fork to posix_spawn or properly set pthread_atfork which will cleanup all the parent process resources. And I am pretty sure that issue here somehow related to this one