facebook / facebook/wangle

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

Open
#230 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
3.1k
Forks
547
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/facebook/wangle/assets/22865114/a76cdf0b-cb60-4bb7-8880-8d8354e3e9ef)
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](__a=0x0000000000000100, __delta=1, __order=memory_order_relaxed) at atomic:1009:12
frame #1: 0x0000000107db4943 ssl_client`std::__1::__atomic_base::fetch_add[abi:v15006](this=0x0000000000000100, __op=1, __m=memory_order_relaxed) at atomic:1659:17
frame #2: 0x0000000107fce664 ssl_client`bool folly::AtomicNotificationQueue>::push>(this=0x0000000000000100, args=0x00007ff7b819fc60) at AtomicNotificationQueue-inl.h:211:14
frame #3: 0x0000000107fbb5e8 ssl_client`void folly::EventBaseAtomicNotificationQueue, folly::EventBase::FuncRunner>::putMessage>(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>::__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::~shared_ptr[abi:v15006](this=0x0000600000314158) at shared_ptr.h:702:23
frame #13: 0x0000000107d8e705 ssl_client`std::__1::shared_ptr::~shared_ptr[abi:v15006](this=0x0000600000314158) at shared_ptr.h:700:5
frame #14: 0x0000000107d9334b ssl_client`wangle::ContextImplBase>>>::~ContextImplBase(this=0x0000600000314130) at HandlerContext-inl.h:77:39
frame #15: 0x0000000107d94c6d ssl_client`wangle::ContextImpl::~ContextImpl(this=0x0000600000314118) at HandlerContext-inl.h:176:35
frame #16: 0x0000000107d93385 ssl_client`wangle::ContextImpl::~ContextImpl(this=0x0000600000314118) at HandlerContext-inl.h:176:35
frame #17: 0x0000000107d92f5d ssl_client`std::__1::__shared_ptr_emplace, std::__1::allocator>>::__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::~shared_ptr[abi:v15006](this=0x000060000031c200) at shared_ptr.h:702:23
frame #21: 0x0000000107d8cea5 ssl_client`std::__1::shared_ptr::~shared_ptr[abi:v15006](this=0x000060000031c200) at shared_ptr.h:700:5
frame #22: 0x0000000107d8d699 ssl_client`std::__1::allocator>::destroy[abi:v15006](this=0x000060000141c2c8, __p=0x000060000031c200) at allocator.h:170:15
frame #23: 0x0000000107d8d66d ssl_client`void std::__1::allocator_traits>>::destroy[abi:v15006], void>(__a=0x000060000141c2c8, __p=0x000060000031c200) at allocator_traits.h:309:13
frame #24: 0x0000000107d8d628 ssl_client`std::__1::vector, std::__1::allocator>>::__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::allocator>>::__clear[abi:v15006](this=0x000060000141c2b8 size=5) at vector:827:29
frame #26: 0x0000000107d8d3be ssl_client`std::__1::vector, std::__1::allocator>>::~vector[abi:v15006](this=0x000060000141c2b8 size=5) at vector:436:9
frame #27: 0x0000000107d8cf05 ssl_client`std::__1::vector, std::__1::allocator>>::~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, std::__1::allocator>>::~Pipeline(this=0x000060000141c2a0) at Pipeline-inl.h:36:1
frame #30: 0x0000000107d8c4b5 ssl_client`wangle::Pipeline, std::__1::allocator>>::~Pipeline(this=0x000060000141c2a0) at Pipeline-inl.h:32:29
frame #31: 0x0000000107d8c4d9 ssl_client`wangle::Pipeline, std::__1::allocator>>::~Pipeline(this=0x000060000141c2a0) at Pipeline-inl.h:32:29
frame #32: 0x0000000107d8e1fc ssl_client`std::__1::default_delete, std::__1::allocator>>>::operator()[abi:v15006](this=0x0000600002d101d8, __ptr=0x000060000141c2a0) const at unique_ptr.h:48:5
frame #33: 0x0000000107d8e09a ssl_client`std::__1::__shared_ptr_pointer, std::__1::allocator>>*, std::__1::shared_ptr, std::__1::allocator>>>::__shared_ptr_default_delete, std::__1::allocator>>, wangle::Pipeline, std::__1::allocator>>>, std::__1::allocator, std::__1::allocator>>>>::__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, std::__1::allocator>>>::~shared_ptr[abi:v15006](this=0x00007ff7b81a0648) at shared_ptr.h:702:23
frame #37: 0x0000000107d695f5 ssl_client`std::__1::shared_ptr, std::__1::allocator>>>::~shared_ptr[abi:v15006](this=0x00007ff7b81a0648) at shared_ptr.h:700:5
frame #38: 0x0000000107d6956c ssl_client`wangle::BaseClientBootstrap, std::__1::allocator>>>::~BaseClientBootstrap(this=0x00007ff7b81a0630) at BaseClientBootstrap.h:75:42
frame #39: 0x0000000107d694f9 ssl_client`wangle::ClientBootstrap, std::__1::allocator>>>::~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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.