I ran into this while shutting my node down during IBD. I think it's benign.
What happens:
CConnmanis started here.- This initializes
semOutboundhere.
- This initializes
- While
CConnmanis active,m_reconnectionsis added to inDisconnectNodeshere. CConnmanis stopped here- The call to
Stopwill callStopNodeswhich will resetsemOutboundhere.
- The call to
~CConnmanis invoked a few lines below here.- In addition to calling
Stopa second time, it also destructs a possibly non-emptym_reconnections(a list ofReconnectionInfowhich contains a pointer to the memory thatsemOutboundalso pointed to) by callingclear(). To destroy each element ofm_reconnections, it looks like it accesses thegrantfield but that memory was already freed.
- In addition to calling
I haven't been able to reproduce this reliably, it appears timing-dependent. I think this can be fixed by calling WITH_LOCK(m_reconnections_mutex, m_reconnections.clear()) before this line.
ASAN output:
=================================================================
==22244==ERROR: AddressSanitizer: heap-use-after-free on address 0x6020018ba9d0 at pc 0x000100837e58 bp 0x00016f826280 sp 0x00016f826278
WRITE of size 8 at 0x6020018ba9d0 thread T0
==22244==WARNING: Can't write to symbolizer at fd 5
[#0](/bitcoin-bitcoin/0/) 0x100837e54 in void std::__1::__destroy_at[abi:ne180100]<CConnman::ReconnectionInfo, 0>(CConnman::ReconnectionInfo*) construct_at.h:67
[#1](/bitcoin-bitcoin/1/) 0x100837754 in std::__1::__list_imp<CConnman::ReconnectionInfo, std::__1::allocator<CConnman::ReconnectionInfo>>::clear() list:635
[#2](/bitcoin-bitcoin/2/) 0x1008202b8 in CConnman::~CConnman() net.cpp:3526
[#3](/bitcoin-bitcoin/3/) 0x10075802c in Shutdown(node::NodeContext&) init.cpp:328
[#4](/bitcoin-bitcoin/4/) 0x1005decc0 in main bitcoind.cpp:292
[#5](/bitcoin-bitcoin/5/) 0x1937bab48 (<unknown module>)
0x6020018ba9d0 is located 0 bytes inside of 8-byte region [0x6020018ba9d0,0x6020018ba9d8)
freed by thread T0 here:
[#0](/bitcoin-bitcoin/0/) 0x1034ed2e4 in _ZdlPv+0x6c (libclang_rt.asan_osx_dynamic.dylib:arm64+0x612e4)
[#1](/bitcoin-bitcoin/1/) 0x10081fe9c in CConnman::StopNodes() net.cpp:3511
[#2](/bitcoin-bitcoin/2/) 0x100757ebc in Shutdown(node::NodeContext&) init.cpp:315
[#3](/bitcoin-bitcoin/3/) 0x1005decc0 in main bitcoind.cpp:292
[#4](/bitcoin-bitcoin/4/) 0x1937bab48 (<unknown module>)
previously allocated by thread T0 here:
[#0](/bitcoin-bitcoin/0/) 0x1034ececc in _Znwm+0x6c (libclang_rt.asan_osx_dynamic.dylib:arm64+0x60ecc)
[#1](/bitcoin-bitcoin/1/) 0x10081c77c in CConnman::Start(CScheduler&, CConnman::Options const&) net.cpp:3361
[#2](/bitcoin-bitcoin/2/) 0x10077d364 in AppInitMain(node::NodeContext&, interfaces::BlockAndHeaderTipInfo*) init.cpp:2183
[#3](/bitcoin-bitcoin/3/) 0x1005debd0 in main bitcoind.cpp:288
[#4](/bitcoin-bitcoin/4/) 0x1937bab48 (<unknown module>)
SUMMARY: AddressSanitizer: heap-use-after-free construct_at.h:67 in void std::__1::__destroy_at[abi:ne180100]<CConnman::ReconnectionInfo, 0>(CConnman::ReconnectionInfo*)
Shadow bytes around the buggy address:
0x6020018ba700: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa
0x6020018ba780: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa
0x6020018ba800: fa fa fd fd fa fa fd fa fa fa fa fa fa fa fa fa
0x6020018ba880: fa fa 00 00 fa fa fa fa fa fa fa fa fa fa 00 00
0x6020018ba900: fa fa fd fa fa fa fd fd fa fa fd fa fa fa fd fd
=>0x6020018ba980: fa fa fd fd fa fa fd fd fa fa[fd]fa fa fa fd fa
0x6020018baa00: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa
0x6020018baa80: fa fa fd fa fa fa fd fd fa fa fa fa fa fa fa fa
0x6020018bab00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x6020018bab80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x6020018bac00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==22244==ABORTING