Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructor failing while calling derived class function #2722

Closed
pitiwari opened this issue Mar 5, 2018 · 2 comments
Closed

Destructor failing while calling derived class function #2722

pitiwari opened this issue Mar 5, 2018 · 2 comments
Labels
question Questions that are neither investigations, bugs, nor enhancements

Comments

@pitiwari
Copy link
Contributor

pitiwari commented Mar 5, 2018

Found this issue while trying to Create CounterImpl class in envoy/source/common/stats/stats_impl.h .Need some help in fixing it

Title: Destructor failing while calling the derived class function

Description:
Found this issue while trying to Create CounterImpl class in envoy/source/common/stats/stats_impl.h. CounterImpl destructor is calling alloc of the derived class since base class RawStatDataAllocator is pure virtual class but by the time we reach destructor of the base class derived class reference is already lost so we cannot call alloc from the destructor.

Below is how i was creating object

Stats::HeapRawStatDataAllocator alloc_;
Stats::RawStatData *data = alloc_.alloc(name);
Stats::CounterSharedPtr c1(new Stats::CounterImpl(*data, alloc_, std::string(name),std::move(tags)));

I am in the middle of changing HeapRawStatDataAllocator destructor to deallocate the memory which was allocated by alloc but getting segmentation fault via tcmalloc. Below is the back trace

Program received signal SIGSEGV, Segmentation fault.
tcmalloc::SLL_PopRange (end=, start=, N=23, head=0x17ceda0) at src/linked_list.h:88
88 src/linked_list.h: No such file or directory.
(gdb) bt
#0 tcmalloc::SLL_PopRange (end=, start=, N=23, head=0x17ceda0) at src/linked_list.h:88
#1 tcmalloc::ThreadCache::FreeList::PopRange (end=, start=, N=23, this=0x17ceda0) at src/thread_cache.h:238
#2 tcmalloc::ThreadCache::ReleaseToCentralCache (this=this@entry=0x17cec40, src=src@entry=0x17ceda0, cl=cl@entry=11, N=23) at src/thread_cache.cc:200
#3 0x0000000000f314e7 in tcmalloc::ThreadCache::Scavenge (this=0x17cec40) at src/thread_cache.cc:218
#4 0x000000000045e6fd in Envoy::Server::AdminFilterTest_Trailers_Test::~AdminFilterTest_Trailers_Test (this=0x2178000, _in_chrg=) at test/server/http/admin_test.cc:56
#5 0x0000000000ee9d58 in testing::Test::DeleteSelf
(this=0x2178000) at external/com_google_googletest/googletest/include/gtest/gtest.h:453
#6 0x0000000000ef3135 in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void> (object=0x2178000,
method=(void (testing::Test::)(testing::Test * const)) 0xee9d2e testing::Test::DeleteSelf_(), location=0x10cc4e7 "the test fixture's destructor")
at external/com_google_googletest/googletest/src/gtest.cc:2401
#7 0x0000000000eef221 in testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void> (object=0x2178000,
method=(void (testing::Test::
)(testing::Test * const)) 0xee9d2e testing::Test::DeleteSelf_(), location=0x10cc4e7 "the test fixture's destructor")
at external/com_google_googletest/googletest/src/gtest.cc:2437
#8 0x0000000000edf31f in testing::TestInfo::Run (this=0x1f90d80) at external/com_google_googletest/googletest/src/gtest.cc:2661
#9 0x0000000000edf927 in testing::TestCase::Run (this=0x1f92100) at external/com_google_googletest/googletest/src/gtest.cc:2773
#10 0x0000000000ee6a53 in testing::internal::UnitTestImpl::RunAllTests (this=0x1f82000) at external/com_google_googletest/googletest/src/gtest.cc:4673
#11 0x0000000000ef3e5d in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x1f82000,
method=(bool (testing::internal::UnitTestImpl::)(testing::internal::UnitTestImpl * const)) 0xee6758 testing::internal::UnitTestImpl::RunAllTests(),
location=0x10ccb90 "auxiliary test code (environments or event listeners)") at external/com_google_googletest/googletest/src/gtest.cc:2401
#12 0x0000000000eefe1b in testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x1f82000,
method=(bool (testing::internal::UnitTestImpl::
)(testing::internal::UnitTestImpl * const)) 0xee6758 testing::internal::UnitTestImpl::RunAllTests(),
location=0x10ccb90 "auxiliary test code (environments or event listeners)") at external/com_google_googletest/googletest/src/gtest.cc:2437
#13 0x0000000000ee55e3 in testing::UnitTest::Run (this=0x15bff40 testing::UnitTest::GetInstance()::instance) at external/com_google_googletest/googletest/src/gtest.cc:4281
#14 0x00000000009b82cc in RUN_ALL_TESTS () at external/com_google_googletest/googletest/include/gtest/gtest.h:2237
#15 0x00000000009b845e in Envoy::TestRunner::RunTests (argc=1, argv=0x7fffffffda68) at ./test/test_runner.h:33
#16 0x00000000009b7450 in main (argc=2, argv=0x7fffffffda68) at test/main.cc:35

Desired Behaviour:
No segmentation fault and memory leak.

@mattklein123 mattklein123 added the question Questions that are neither investigations, bugs, nor enhancements label Mar 5, 2018
@htuch
Copy link
Member

htuch commented Mar 6, 2018

@pitiwari I'm not sure how much we can assist without a full tree and exact invocation details, but this is then getting into territory where we would expect most developers to be able to support themselves. I would recommend running ASAN/TSAN and seeing if anything more descriptive shows up to help, see https://github.com/envoyproxy/envoy/tree/master/ci#building-and-running-tests-as-a-developer and https://github.com/envoyproxy/envoy/blob/master/bazel/README.md#sanitizers.

pitiwari added a commit to pitiwari/envoy that referenced this issue Mar 7, 2018
       Destructor failig while calling derived class function envoyproxy#2722
Description:

The admin endpoint of envoy when queried as a prometheus endpoint fails promlint.
Promlint is a sanity check tool offered by Prometheus to check the correctness
of a prometheus endpoint.

following issues were fixed
-fixed issue with metric type being prtinted twice
-added unit test as well
-fixed issue in destructors of CounterImpl and GuageImpl
-changed thread_local_store_test to remove check for count of free func calls

Signed-off-by: Piyush Tiwari <pitiwari@ebay.com>
@mattklein123
Copy link
Member

I believe this was figured out. Closing.

Shikugawa pushed a commit to Shikugawa/envoy that referenced this issue Mar 28, 2020
* use envoy_cc_library in sd extension

* fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions that are neither investigations, bugs, nor enhancements
Projects
None yet
Development

No branches or pull requests

3 participants