Skip to content

Commit d907af1

Browse files
committed
MB-70173: Don't use static storage for MockConnection's description
This is the problematic code: const T& MockConnection::getDescription() const { static T obj{..}; return obj; } Problem with that is that in ep_testsuite that memory is (1) allocated the first time the function is called (which is in a Bucket context) and (2) then released when the program shuts down (ie outside Bucket context, as at that point any bucket instance as been already released). In local testing that shows up like % env CB_ARENA_MALLOC_VERIFY_DEALLOC_CLIENT=1 lldb -- ../source_morpheus/build/kv_engine/ep_testsuite_dcp "-v" "-e" "compression_mode=active;item_eviction_policy=full_eviction;dbname=./ep_testsuite_dcp.full_eviction.comp_active.db" -C 90 (lldb) pr la Process 11613 launched: '../source_morpheus/build/kv_engine/ep_testsuite_dcp' (arm64) Running [90/91]: test oso backfill...(125 ms) OK ===ERROR===: JeArenaMalloc deallocation mismatch Memory freed by client:100 domain:None which is assigned arena:0, but memory was previously allocated from arena:2 (client-specific arena). Allocation address:0x1047fe4a0 size:24 .. Process 11613 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT frame #0: 0x00000001816955f0 libsystem_kernel.dylib` __pthread_kill + 8 libsystem_kernel.dylib`: -> 0x1816955f0 <+8>: b.lo 0x181695610 ; <+40> 0x1816955f4 <+12>: pacibsp 0x1816955f8 <+16>: stp x29, x30, [sp, #-0x10]! 0x1816955fc <+20>: mov x29, sp Target 0: (ep_testsuite_dcp) stopped. (lldb) bt * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT * frame #0: 0x00000001816955f0 libsystem_kernel.dylib` __pthread_kill + 8 frame #1: 0x00000001816cdc20 libsystem_pthread.dylib` pthread_kill + 288 frame #2: 0x00000001815daa30 libsystem_c.dylib` abort + 180 frame #3: 0x0000000100fb71a8 ep_testsuite_dcp` cb::verifyMemDeallocatedByCorrectClient(client=0x000000016fdfeca8, ptr=0x00000001047fe4a0, size=24) + 536 at je_arena_malloc.cc:260 frame #4: 0x0000000100fb7238 ep_testsuite_dcp` cb::_JEArenaMalloc<cb::JEArenaSimpleTracker>::sized_free(ptr=0x00000001047fe4a0, size=24) + 84 at je_arena_malloc.cc:455 frame #5: 0x00000001000e29f4 ep_testsuite_dcp` cb::_ArenaMalloc<cb::_JEArenaMalloc<cb::JEArenaSimpleTracker>>::sized_free(ptr=0x00000001047fe4a0, size=24) + 32 at cb_arena_malloc.h:273 frame #6: 0x00000001000e29c0 ep_testsuite_dcp` cb_sized_free(ptr=0x00000001047fe4a0, size=24) + 44 at cb_malloc_arena.cc:75 frame #7: 0x00000001000e2fcc ep_testsuite_dcp` operator delete(ptr=0x00000001047fe4a0, size=24) + 32 at global_new_replacement.cc:146 frame #8: 0x0000000100030a24 ep_testsuite_dcp` void std::__1::__libcpp_operator_delete[abi:ue170006]<void*, unsigned long>(__args=0x00000001047fe4a0, __args=24) + 32 at new:308 frame #9: 0x00000001000309c4 ep_testsuite_dcp` void std::__1::__do_deallocate_handle_size[abi:ue170006]<>(__ptr=0x00000001047fe4a0, __size=24) + 32 at new:334 frame #10: 0x0000000100030960 ep_testsuite_dcp` std::__1::__libcpp_deallocate[abi:ue170006](__ptr=0x00000001047fe4a0, __size=24, __align=8) + 80 at new:348 frame #11: 0x00000001000676b4 ep_testsuite_dcp` std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>::deallocate[abi:ue170006](this=0x000000016fdfee85, __p="me", __n=1) + 48 at allocator.h:130 frame #12: 0x0000000100067678 ep_testsuite_dcp` std::__1::allocator_traits<std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::deallocate[abi:ue170006](__a=0x000000016fdfee85, __p="me", __n=1) + 40 at allocator_traits.h:288 frame #13: 0x000000010007c964 ep_testsuite_dcp` nlohmann::json_abi_v3_11_3::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void>::json_value::destroy(this=0x000000016fdff0c0, t=string) + 1212 at json.hpp:646 frame #14: 0x000000010007c490 ep_testsuite_dcp` nlohmann::json_abi_v3_11_3::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void>::data::~data(this=0x000000016fdff0b8) + 36 at json.hpp:4225 frame #15: 0x0000000100077fb8 ep_testsuite_dcp` nlohmann::json_abi_v3_11_3::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void>::data::~data(this=0x000000016fdff0b8) + 28 at json.hpp:4224 frame #16: 0x0000000100085e58 ep_testsuite_dcp` nlohmann::json_abi_v3_11_3::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void>::~basic_json(this=0x000000016fdff0b8) + 44 at json.hpp:1266 frame #17: 0x0000000100064694 ep_testsuite_dcp` nlohmann::json_abi_v3_11_3::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void>::~basic_json(this=0x000000016fdff0b8) + 28 at json.hpp:1264 frame #18: 0x000000010007c874 ep_testsuite_dcp` nlohmann::json_abi_v3_11_3::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void>::json_value::destroy(this=0x0000000101500b80, t=object) + 972 at json.hpp:621 frame #19: 0x000000010007c490 ep_testsuite_dcp` nlohmann::json_abi_v3_11_3::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void>::data::~data(this=0x0000000101500b78) + 36 at json.hpp:4225 frame #20: 0x0000000100077fb8 ep_testsuite_dcp` nlohmann::json_abi_v3_11_3::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void>::data::~data(this=0x0000000101500b78) + 28 at json.hpp:4224 frame #21: 0x0000000100085e58 ep_testsuite_dcp` nlohmann::json_abi_v3_11_3::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void>::~basic_json(this=0x0000000101500b78) + 44 at json.hpp:1266 frame #22: 0x0000000100064694 ep_testsuite_dcp` nlohmann::json_abi_v3_11_3::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::json_abi_v3_11_3::adl_serializer, std::__1::vector<unsigned char, std::__1::allocator<unsigned char>>, void>::~basic_json(this=0x0000000101500b78) + 28 at json.hpp:1264 frame #23: 0x000000018158b2e8 libsystem_c.dylib` __cxa_finalize_ranges + 476 frame #24: 0x000000018158b070 libsystem_c.dylib` exit + 44 frame #25: 0x00000001816e6850 libdyld.dylib` dyld4::LibSystemHelpers::exit(int) const + 20 frame #26: 0x00000001813431a0 dyld` start + 2552 Change-Id: I6e4b8203eb5dfd67352386895d87dfd52f6c6641 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/238640 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Paolo Cocchi <paolo.cocchi@couchbase.com> Well-Formed: Restriction Checker Reviewed-by: Mohammad Zaeem <mohammad.zaeem@couchbase.com>
1 parent eff409c commit d907af1

2 files changed

Lines changed: 1 addition & 1 deletion

File tree

programs/engine_testapp/mock_cookie.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ void MockConnection::setUserScheduleDcpStep(std::function<void()> func) {
2626
userScheduleDcpStep = std::move(func);
2727
}
2828
const nlohmann::json& MockConnection::getDescription() const {
29-
static nlohmann::json description{{"peer", "you"}, {"socket", "me"}};
3029
return description;
3130
}
3231
const cb::rbac::UserIdent& MockConnection::getUser() const {

programs/engine_testapp/mock_cookie.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class MockConnection : public ConnectionIface {
5353
protected:
5454
ConnectionPriority priority{ConnectionPriority::Medium};
5555
cb::rbac::UserIdent user{"nobody", cb::rbac::Domain::Local};
56+
const nlohmann::json description{{"peer", "you"}, {"socket", "me"}};
5657
};
5758

5859
class MockCookie : public CookieIface {

0 commit comments

Comments
 (0)