mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Improving error handling for threads.
If a thread command fails (like the input framework not finding a file), that now (1) no longer hangs Bro, and (2) even allows for propagating error messages back before the thread is stops. (Actually, the thread doesn't really "stop"; the thread manager keeps threads around independent of their success; but it no longer polls them for input.) Closes #858.
This commit is contained in:
parent
ef3b75129f
commit
743fc1680d
3 changed files with 39 additions and 14 deletions
|
@ -70,6 +70,16 @@ private:
|
|||
Type type;
|
||||
};
|
||||
|
||||
// A message from the the child to the main process, requesting suicide.
|
||||
class KillMeMessage : public OutputMessage<MsgThread>
|
||||
{
|
||||
public:
|
||||
KillMeMessage(MsgThread* thread)
|
||||
: OutputMessage<MsgThread>("ReporterMessage", thread) {}
|
||||
|
||||
virtual bool Process() { thread_mgr->KillThread(Object()); return true; }
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
// A debug message from the child to be passed on to the DebugLogger.
|
||||
class DebugMessage : public OutputMessage<MsgThread>
|
||||
|
@ -346,16 +356,20 @@ void MsgThread::Run()
|
|||
|
||||
if ( ! result )
|
||||
{
|
||||
string s = Fmt("%s failed, terminating thread (MsgThread)", Name());
|
||||
Error(s.c_str());
|
||||
break;
|
||||
Error("terminating thread");
|
||||
|
||||
// This will eventually kill this thread, but only
|
||||
// after all other outgoing messages (in particular
|
||||
// error messages have been processed by then main
|
||||
// thread).
|
||||
SendOut(new KillMeMessage(this));
|
||||
}
|
||||
}
|
||||
|
||||
// In case we haven't send the finish method yet, do it now. Reading
|
||||
// global network_time here should be fine, it isn't changing
|
||||
// anymore.
|
||||
if ( ! finished )
|
||||
if ( ! finished && ! Killed() )
|
||||
{
|
||||
OnFinish(network_time);
|
||||
Finished();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue