-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Fix frequent segmentation fault of Python tests by refactoring ExecutorService #12427
Fix frequent segmentation fault of Python tests by refactoring ExecutorService #12427
Conversation
Though it has been verified in my local env for many times, I'm still looking forward to what will happen in CI. Please don't rerun the cpp tests if it failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @BewareMyPower !
|
…orService (apache#12427) * Refactor ExecutorService to avoid usage of pointers * Remove unnecessary friend class * Fix CentOS 7 build * Fix PeriodicalTest
Fixes #11635
Motivation
Python tests failed very often with segmentation fault. It can be reproduced easily based on the
apachepulsar/pulsar-build:ubuntu-16.04-pb3
image in local env. After dumping the core file and runninggdb python core
to debug, we can see the following backtrace.The
io_service
object is not null, but the internalimpl_
field, whose type is atask_io_service
pointer, is null (see(this=0x0
of#2
).The cause is
io_service::run
is called in a dependent thread, while the destructor ofExecutorService
is called in another thread. After theExecutorService
is destructed, the internal thread fieldworker_
and theio_service
field will both be invalid to access.io_service::run
should not be called after that.Modifications
Refactor the
ExecutorService
. Since it's not copyable, it's redundant to storeio_service
andio_service::work
as smart pointers. In addition, the thread that runsio_service
is never used, just detach it whenExecutorService
is created.The key point is to check whether
ExecutorService#close
is called in the thread by examining the atomic boolean valueclosed_
. Besides, the shared pointer is captured in the thread so that theExecutorService
's lifetime could be extended.