facebook / wangle

Wangle is a framework providing a set of common client/server abstractions for building services in a consistent, modular, and composable way.
Apache License 2.0
3.05k stars 539 forks source link

[bug] Destruction of ClientBootstrap failed because of visiting destructed socket's EventBase #230

Open HolyLow opened 4 months ago

HolyLow commented 4 months ago

I am trying to run the examples of wangle. When running the ssl example in https://github.com/facebook/wangle/tree/main/wangle/example/ssl (with self-written cmakelist file to add the necessary dependencies), the Client code failed when I typed 'bye' to finish the execution. When testing, I manually set the ssl option to false to avoid any problem from ssl related code. The code failed when the ClientBootstrap is destructing, and the stack in the debugger is as follows: image To get more detailed stack, I used the LLDB to show the thread frame:

(lldb) thread backtrace
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x100)
  * frame #0: 0x0000000107db499f ssl_client`long std::__1::__cxx_atomic_fetch_add[abi:v15006]<long>(__a=0x0000000000000100, __delta=1, __order=memory_order_relaxed) at atomic:1009:12
    frame #1: 0x0000000107db4943 ssl_client`std::__1::__atomic_base<long, true>::fetch_add[abi:v15006](this=0x0000000000000100, __op=1, __m=memory_order_relaxed) at atomic:1659:17
    frame #2: 0x0000000107fce664 ssl_client`bool folly::AtomicNotificationQueue<folly::Function<void ()>>::push<folly::Function<void ()>>(this=0x0000000000000100, args=0x00007ff7b819fc60) at AtomicNotificationQueue-inl.h:211:14
    frame #3: 0x0000000107fbb5e8 ssl_client`void folly::EventBaseAtomicNotificationQueue<folly::Function<void ()>, folly::EventBase::FuncRunner>::putMessage<folly::Function<void ()>>(this=0x0000000000000000, args=0x00007ff7b819fc60) at EventBaseAtomicNotificationQueue-inl.h:133:26
    frame #4: 0x0000000107fb667f ssl_client`folly::EventBase::runInEventBaseThread(this=0x00007fc5b95044e0, fn=folly::EventBase::Func @ 0x00007ff7b819fc60) at EventBase.cpp:879:11
    frame #5: 0x0000000107fbb888 ssl_client`folly::EventBase::runInEventBaseThreadAndWait(this=0x00007fc5b95044e0, fn=folly::EventBase::Func @ 0x00007ff7b819fce0) at EventBase.cpp:904:3
    frame #6: 0x0000000107fbbb00 ssl_client`folly::EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(this=0x00007fc5b95044e0, fn=folly::EventBase::Func @ 0x00007ff7b819fd80) at EventBase.cpp:917:5
    frame #7: 0x0000000107da03d6 ssl_client`wangle::AsyncSocketHandler::~AsyncSocketHandler(this=0x0000600001c18018) at AsyncSocketHandler.h:43:14
    frame #8: 0x0000000107d8c0a5 ssl_client`wangle::AsyncSocketHandler::~AsyncSocketHandler(this=0x0000600001c18018) at AsyncSocketHandler.h:37:34
    frame #9: 0x0000000107d9b31d ssl_client`std::__1::__shared_ptr_emplace<wangle::AsyncSocketHandler, std::__1::allocator<wangle::AsyncSocketHandler>>::__on_zero_shared(this=0x0000600001c18000) at shared_ptr.h:311:24
    frame #10: 0x0000000107d68ac1 ssl_client`std::__1::__shared_count::__release_shared[abi:v15006](this=0x0000600001c18000) at shared_ptr.h:174:9
    frame #11: 0x0000000107d68a69 ssl_client`std::__1::__shared_weak_count::__release_shared[abi:v15006](this=0x0000600001c18000) at shared_ptr.h:215:27
    frame #12: 0x0000000107da014c ssl_client`std::__1::shared_ptr<wangle::AsyncSocketHandler>::~shared_ptr[abi:v15006](this=0x0000600000314158) at shared_ptr.h:702:23
    frame #13: 0x0000000107d8e705 ssl_client`std::__1::shared_ptr<wangle::AsyncSocketHandler>::~shared_ptr[abi:v15006](this=0x0000600000314158) at shared_ptr.h:700:5
    frame #14: 0x0000000107d9334b ssl_client`wangle::ContextImplBase<wangle::AsyncSocketHandler, wangle::HandlerContext<folly::IOBufQueue&, std::__1::unique_ptr<folly::IOBuf, std::__1::default_delete<folly::IOBuf>>>>::~ContextImplBase(this=0x0000600000314130) at HandlerContext-inl.h:77:39
    frame #15: 0x0000000107d94c6d ssl_client`wangle::ContextImpl<wangle::AsyncSocketHandler>::~ContextImpl(this=0x0000600000314118) at HandlerContext-inl.h:176:35
    frame #16: 0x0000000107d93385 ssl_client`wangle::ContextImpl<wangle::AsyncSocketHandler>::~ContextImpl(this=0x0000600000314118) at HandlerContext-inl.h:176:35
    frame #17: 0x0000000107d92f5d ssl_client`std::__1::__shared_ptr_emplace<wangle::ContextImpl<wangle::AsyncSocketHandler>, std::__1::allocator<wangle::ContextImpl<wangle::AsyncSocketHandler>>>::__on_zero_shared(this=0x0000600000314100) at shared_ptr.h:311:24
    frame #18: 0x0000000107d68ac1 ssl_client`std::__1::__shared_count::__release_shared[abi:v15006](this=0x0000600000314100) at shared_ptr.h:174:9
    frame #19: 0x0000000107d68a69 ssl_client`std::__1::__shared_weak_count::__release_shared[abi:v15006](this=0x0000600000314100) at shared_ptr.h:215:27
    frame #20: 0x0000000107d8cf5c ssl_client`std::__1::shared_ptr<wangle::PipelineContext>::~shared_ptr[abi:v15006](this=0x000060000031c200) at shared_ptr.h:702:23
    frame #21: 0x0000000107d8cea5 ssl_client`std::__1::shared_ptr<wangle::PipelineContext>::~shared_ptr[abi:v15006](this=0x000060000031c200) at shared_ptr.h:700:5
    frame #22: 0x0000000107d8d699 ssl_client`std::__1::allocator<std::__1::shared_ptr<wangle::PipelineContext>>::destroy[abi:v15006](this=0x000060000141c2c8, __p=0x000060000031c200) at allocator.h:170:15
    frame #23: 0x0000000107d8d66d ssl_client`void std::__1::allocator_traits<std::__1::allocator<std::__1::shared_ptr<wangle::PipelineContext>>>::destroy[abi:v15006]<std::__1::shared_ptr<wangle::PipelineContext>, void>(__a=0x000060000141c2c8, __p=0x000060000031c200) at allocator_traits.h:309:13
    frame #24: 0x0000000107d8d628 ssl_client`std::__1::vector<std::__1::shared_ptr<wangle::PipelineContext>, std::__1::allocator<std::__1::shared_ptr<wangle::PipelineContext>>>::__base_destruct_at_end[abi:v15006](this=0x000060000141c2b8 size=5, __new_last=0x000060000031c200) at vector:833:9
    frame #25: 0x0000000107d8d4d8 ssl_client`std::__1::vector<std::__1::shared_ptr<wangle::PipelineContext>, std::__1::allocator<std::__1::shared_ptr<wangle::PipelineContext>>>::__clear[abi:v15006](this=0x000060000141c2b8 size=5) at vector:827:29
    frame #26: 0x0000000107d8d3be ssl_client`std::__1::vector<std::__1::shared_ptr<wangle::PipelineContext>, std::__1::allocator<std::__1::shared_ptr<wangle::PipelineContext>>>::~vector[abi:v15006](this=0x000060000141c2b8 size=5) at vector:436:9
    frame #27: 0x0000000107d8cf05 ssl_client`std::__1::vector<std::__1::shared_ptr<wangle::PipelineContext>, std::__1::allocator<std::__1::shared_ptr<wangle::PipelineContext>>>::~vector[abi:v15006](this=0x000060000141c2b8 size=5) at vector:430:5
    frame #28: 0x0000000107d8ce2f ssl_client`wangle::PipelineBase::~PipelineBase(this=0x000060000141c2a0) at Pipeline.h:49:35
    frame #29: 0x0000000107d8cd8b ssl_client`wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>::~Pipeline(this=0x000060000141c2a0) at Pipeline-inl.h:36:1
    frame #30: 0x0000000107d8c4b5 ssl_client`wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>::~Pipeline(this=0x000060000141c2a0) at Pipeline-inl.h:32:29
    frame #31: 0x0000000107d8c4d9 ssl_client`wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>::~Pipeline(this=0x000060000141c2a0) at Pipeline-inl.h:32:29
    frame #32: 0x0000000107d8e1fc ssl_client`std::__1::default_delete<wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::operator()[abi:v15006](this=0x0000600002d101d8, __ptr=0x000060000141c2a0) const at unique_ptr.h:48:5
    frame #33: 0x0000000107d8e09a ssl_client`std::__1::__shared_ptr_pointer<wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>*, std::__1::shared_ptr<wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::__shared_ptr_default_delete<wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>, std::__1::allocator<wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>>::__on_zero_shared(this=0x0000600002d101c0) at shared_ptr.h:263:5
    frame #34: 0x0000000107d68ac1 ssl_client`std::__1::__shared_count::__release_shared[abi:v15006](this=0x0000600002d101c0) at shared_ptr.h:174:9
    frame #35: 0x0000000107d68a69 ssl_client`std::__1::__shared_weak_count::__release_shared[abi:v15006](this=0x0000600002d101c0) at shared_ptr.h:215:27
    frame #36: 0x0000000107d69efc ssl_client`std::__1::shared_ptr<wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::~shared_ptr[abi:v15006](this=0x00007ff7b81a0648) at shared_ptr.h:702:23
    frame #37: 0x0000000107d695f5 ssl_client`std::__1::shared_ptr<wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::~shared_ptr[abi:v15006](this=0x00007ff7b81a0648) at shared_ptr.h:700:5
    frame #38: 0x0000000107d6956c ssl_client`wangle::BaseClientBootstrap<wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::~BaseClientBootstrap(this=0x00007ff7b81a0630) at BaseClientBootstrap.h:75:42
    frame #39: 0x0000000107d694f9 ssl_client`wangle::ClientBootstrap<wangle::Pipeline<folly::IOBufQueue&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::~ClientBootstrap(this=0x00007ff7b81a0630) at ClientBootstrap.h:137:39
    frame #40: 0x0000000107d6bf75 ssl_client`(anonymous namespace)::EchoClientBootstrap::~EchoClientBootstrap(this=0x00007ff7b81a0630) at Client.cpp:90:7
    frame #41: 0x0000000107d68815 ssl_client`(anonymous namespace)::EchoClientBootstrap::~EchoClientBootstrap(this=0x00007ff7b81a0630) at Client.cpp:90:7
    frame #42: 0x0000000107d675c7 ssl_client`main(argc=1, argv=0x00007ff7b81a0aa8) at Client.cpp:174:1
    frame #43: 0x00007ff81b2b341f dyld`start + 1903

It seems that the AsyncSocketHandler's destructor visits a nullptr in the following line: https://github.com/facebook/wangle/blob/cf7349f22b8327117a6ed37272333442daadf5fd/wangle/channel/AsyncSocketHandler.h#L43

My environment is MapbookPro2019 with intel i7, macOS Ventura 13.4.1., compiler is AppleClang 14.0.3.

I have no idea why I encountered this problem as I am just running the standard example! Could someone help me?

HolyLow commented 4 months ago

@Orvid Seems the community is not active except you. Could you offer some help or route this issue to someone who can help? Thanks a lot.

Orvid commented 4 months ago

Unfortunately, I don't know a lot about the ssl setup, so I'm not actually sure what's going wrong here.