Mercurial > hg > orthanc-stone
diff Framework/Loaders/LoaderStateMachine.cpp @ 973:38409549db43 toa2019082903
Log with addresses + added fingerprint mechanism to avoid calling zombie objects
where:
- a message is sent with a receiver
- the receiver dies
- another receiver with the SAME address is created
- the message reply is executed --> execution on the wrong object!
(since their "identity" is their address. The fix is to identify them with
an UUID stored at creation time)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Thu, 29 Aug 2019 18:07:55 +0200 |
parents | 91f827272c1f |
children | e75fd08d6c75 |
line wrap: on
line diff
--- a/Framework/Loaders/LoaderStateMachine.cpp Thu Aug 29 13:12:03 2019 +0200 +++ b/Framework/Loaders/LoaderStateMachine.cpp Thu Aug 29 18:07:55 2019 +0200 @@ -23,11 +23,6 @@ #include <Core/OrthancException.h> -#if 0 -extern bool logbgo233; -extern bool logbgo115; -#endif - namespace OrthancStone { void LoaderStateMachine::State::Handle(const OrthancRestApiCommand::SuccessMessage& message) @@ -50,12 +45,7 @@ void LoaderStateMachine::Schedule(OracleCommandWithPayload* command) { -#if 0 - if (logbgo233) { - if (logbgo115) - LOG(TRACE) << " LoaderStateMachine::Schedule()"; - } -#endif + LOG(TRACE) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::Schedule()"; std::auto_ptr<OracleCommandWithPayload> protection(command); @@ -69,13 +59,6 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, "The payload must contain the next state"); } - -#if 0 - if (logbgo233) { - if (logbgo115) - LOG(TRACE) << " * LoaderStateMachine::Schedule(): adding command with addr: " << std::hex << protection.get() << std::dec << " pendingCommands_.size() is now : " << pendingCommands_.size()+1; - } -#endif pendingCommands_.push_back(protection.release()); Step(); @@ -84,6 +67,8 @@ void LoaderStateMachine::Start() { + LOG(TRACE) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::Start()"; + if (active_) { LOG(TRACE) << "LoaderStateMachine::Start() called while active_ is true"; @@ -101,22 +86,16 @@ void LoaderStateMachine::Step() { -#if 0 - if (logbgo115) - LOG(TRACE) << " LoaderStateMachine::Step(): pendingCommands_.size() = " << pendingCommands_.size(); -#endif if (!pendingCommands_.empty() && activeCommands_ < simultaneousDownloads_) { IOracleCommand* nextCommand = pendingCommands_.front(); -#if 0 - if (logbgo233) { - if (logbgo115) - LOG(TRACE) << " * LoaderStateMachine::Step(): activeCommands_ (" << activeCommands_ << ") < simultaneousDownloads_ (" << simultaneousDownloads_ << ") --> will Schedule command addr " << std::hex << nextCommand << std::dec; - } -#endif + LOG(TRACE) << " LoaderStateMachine(" << std::hex << this << std::dec << + ")::Step(): activeCommands_ (" << activeCommands_ << + ") < simultaneousDownloads_ (" << simultaneousDownloads_ << + ") --> will Schedule command addr " << std::hex << nextCommand << std::dec; oracle_.Schedule(*this, nextCommand); pendingCommands_.pop_front(); @@ -125,18 +104,17 @@ } else { -#if 0 - if (logbgo233) { - if (logbgo115) - LOG(TRACE) << " * pendingCommands_.size() == " << pendingCommands_.size() << " LoaderStateMachine::Step(): activeCommands_ (" << activeCommands_ << ") >= simultaneousDownloads_ (" << simultaneousDownloads_ << ") --> will NOT Schedule anything"; - } -#endif + LOG(TRACE) << " LoaderStateMachine(" << std::hex << this << std::dec << + ")::Step(): activeCommands_ (" << activeCommands_ << + ") < simultaneousDownloads_ (" << simultaneousDownloads_ << + ") --> will NOT Schedule command"; } } void LoaderStateMachine::Clear() { + LOG(TRACE) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::Clear()"; for (PendingCommands::iterator it = pendingCommands_.begin(); it != pendingCommands_.end(); ++it) { @@ -158,7 +136,10 @@ template <typename T> void LoaderStateMachine::HandleSuccessMessage(const T& message) { - assert(activeCommands_ > 0); + LOG(TRACE) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::HandleSuccessMessage()"; + if (activeCommands_ <= 0) { + LOG(ERROR) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::HandleSuccessMessage : activeCommands_ should be > 0 but is: " << activeCommands_; + } activeCommands_--; try @@ -183,6 +164,8 @@ simultaneousDownloads_(4), activeCommands_(0) { + LOG(TRACE) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::LoaderStateMachine()"; + oracleObservable.RegisterObserverCallback( new Callable<LoaderStateMachine, OrthancRestApiCommand::SuccessMessage> (*this, &LoaderStateMachine::HandleSuccessMessage)); @@ -200,6 +183,11 @@ (*this, &LoaderStateMachine::HandleExceptionMessage)); } + LoaderStateMachine::~LoaderStateMachine() + { + LOG(TRACE) << "LoaderStateMachine(" << std::hex << this << std::dec << ")::~LoaderStateMachine()"; + Clear(); + } void LoaderStateMachine::SetSimultaneousDownloads(unsigned int count) {