1
0
Fork 0

try to work around races

This commit is contained in:
jsteemann 2017-05-04 13:10:53 +02:00
parent ab8a4ec176
commit 0d964bc704
2 changed files with 13 additions and 1 deletions

View File

@ -61,6 +61,18 @@ void ListenTask::start() {
}
_handler = [this](boost::system::error_code const& ec) {
// copy the shared_ptr so nobody can delete the Acceptor while the
// callback is running
std::shared_ptr<Acceptor> acceptorCopy(_acceptor);
if (acceptorCopy == nullptr) {
// ListenTask already stopped
return;
}
// now it is safe to use _acceptor
TRI_ASSERT(_acceptor != nullptr);
if (ec) {
if (ec == boost::asio::error::operation_aborted) {
return;

View File

@ -60,7 +60,7 @@ class ListenTask : virtual public rest::Task {
boost::asio::io_service* _ioService;
std::unique_ptr<Acceptor> _acceptor;
std::shared_ptr<Acceptor> _acceptor;
std::function<void(boost::system::error_code const&)> _handler;
};