From bbfbb6a5978f5167702cad8ae7a49c80c6630a35 Mon Sep 17 00:00:00 2001 From: zcui Date: Fri, 30 Mar 2018 08:54:16 -0700 Subject: [PATCH] contrail-collector crash immediately after provisioning root cause: To state_machine_, sandesh_connection is owner as scoped_ptr. generator as user use state_machine_.get() to access. sandesh _connection will deal with connection close message in one core but generator will deal with redis message in another core. This lead source race condition. We have use mutex lock to protect. but mutex is one part of state_machine_ structure, so to destructed fucntion of state_machine_, protecting is invalid. Solution: Change scoped_ptr to shared_ptr. Change-Id: I1756f8dc0cdd1e7b705af9f1650c6bb8b118e212 Partial-Bug: 1755649 --- library/cpp/sandesh_connection.cc | 5 +++++ library/cpp/sandesh_connection.h | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/library/cpp/sandesh_connection.cc b/library/cpp/sandesh_connection.cc index 7f73fdca..82d79332 100644 --- a/library/cpp/sandesh_connection.cc +++ b/library/cpp/sandesh_connection.cc @@ -99,6 +99,11 @@ SandeshStateMachine *SandeshConnection::state_machine() const { return state_machine_.get(); } +boost::shared_ptr +SandeshConnection::shared_state_machine() const { + return state_machine_; +} + void SandeshConnection::SetAdminState(bool down) { if (admin_down_ != down) { admin_down_ = down; diff --git a/library/cpp/sandesh_connection.h b/library/cpp/sandesh_connection.h index c680b8b4..848c9491 100644 --- a/library/cpp/sandesh_connection.h +++ b/library/cpp/sandesh_connection.h @@ -45,6 +45,7 @@ class SandeshConnection { SandeshSession *session() const; SandeshStateMachine *state_machine() const; + boost::shared_ptr shared_state_machine() const; std::string StateName() const { return state_machine_->StateName(); } @@ -91,8 +92,8 @@ class SandeshConnection { SandeshSession *session_; int task_instance_; int task_id_; - boost::scoped_ptr state_machine_; - + boost::shared_ptr state_machine_; + DISALLOW_COPY_AND_ASSIGN(SandeshConnection); };