From c8789cff94c5200674ad08199a1f800882aabf72 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 16 Jul 2012 13:40:19 -0700 Subject: [PATCH] If a thread doesn't terminate, we log that but not longer proceed (because it could hang later still). Also logging to stderr as well to make sure one sees it. Also adding code to the ASCII writer to catch termination inconsistencies. --- aux/binpac | 2 +- aux/bro-aux | 2 +- aux/broccoli | 2 +- aux/broctl | 2 +- cmake | 2 +- src/logging/writers/Ascii.cc | 14 ++++++++++++++ src/logging/writers/Ascii.h | 1 + src/threading/MsgThread.cc | 8 +++----- 8 files changed, 23 insertions(+), 10 deletions(-) diff --git a/aux/binpac b/aux/binpac index 4ad8d15b63..b4094cb75e 160000 --- a/aux/binpac +++ b/aux/binpac @@ -1 +1 @@ -Subproject commit 4ad8d15b6395925c9875c9d2912a6cc3b4918e0a +Subproject commit b4094cb75e0a7769123f7db1f5d73f3f9f1c3977 diff --git a/aux/bro-aux b/aux/bro-aux index c691c01e9c..2038e3de04 160000 --- a/aux/bro-aux +++ b/aux/bro-aux @@ -1 +1 @@ -Subproject commit c691c01e9cefae5a79bcd4b0f84ca387c8c587a7 +Subproject commit 2038e3de042115c3caa706426e16c830c1fd1e9e diff --git a/aux/broccoli b/aux/broccoli index 8234b8903c..07866915a1 160000 --- a/aux/broccoli +++ b/aux/broccoli @@ -1 +1 @@ -Subproject commit 8234b8903cbc775f341bdb6a1c0159981d88d27b +Subproject commit 07866915a1450ddd25b888917f494b4824b0cc3f diff --git a/aux/broctl b/aux/broctl index d5ecd1a42c..892b60edb9 160000 --- a/aux/broctl +++ b/aux/broctl @@ -1 +1 @@ -Subproject commit d5ecd1a42c04b0dca332edc31811e5a6d0f7f2fb +Subproject commit 892b60edb967bb456872638f22ba994e84530137 diff --git a/cmake b/cmake index 2a72c5e08e..96f3d92aca 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 2a72c5e08e018cf632033af3920432d5f684e130 +Subproject commit 96f3d92acadbe1ae64f410e974c5ff503903394b diff --git a/src/logging/writers/Ascii.cc b/src/logging/writers/Ascii.cc index ab68cd77d8..a0d4504d64 100644 --- a/src/logging/writers/Ascii.cc +++ b/src/logging/writers/Ascii.cc @@ -16,6 +16,7 @@ using threading::Field; Ascii::Ascii(WriterFrontend* frontend) : WriterBackend(frontend) { file = 0; + ascii_done = false; output_to_stdout = BifConst::LogAscii::output_to_stdout; include_meta = BifConst::LogAscii::include_meta; @@ -51,6 +52,12 @@ Ascii::Ascii(WriterFrontend* frontend) : WriterBackend(frontend) Ascii::~Ascii() { + if ( ! ascii_done ) + { + fprintf(stderr, "missing finish message\n"); + abort(); + } + // Normally, the file will be closed here already via the Finish() // message. But when we terminate abnormally, we may still have it // open. @@ -156,6 +163,13 @@ bool Ascii::DoFlush(double network_time) bool Ascii::DoFinish(double network_time) { + if ( ascii_done ) + { + fprintf(stderr, "duplicate finish message\n"); + abort(); + } + + ascii_done = true; CloseFile(network_time); return true; } diff --git a/src/logging/writers/Ascii.h b/src/logging/writers/Ascii.h index 857954ce37..c2cd33f203 100644 --- a/src/logging/writers/Ascii.h +++ b/src/logging/writers/Ascii.h @@ -40,6 +40,7 @@ private: FILE* file; string fname; ODesc desc; + bool ascii_done; // Options set from the script-level. bool output_to_stdout; diff --git a/src/threading/MsgThread.cc b/src/threading/MsgThread.cc index 81ef123661..e4cda1e84d 100644 --- a/src/threading/MsgThread.cc +++ b/src/threading/MsgThread.cc @@ -166,17 +166,15 @@ void MsgThread::OnStop() int cnt = 0; while ( ! finished ) { - if ( ++cnt > 1000 ) // Insurance against broken threads ... + if ( ++cnt % 2000 == 0 ) // Insurance against broken threads ... { - reporter->Warning("thread %s didn't finish in time", Name().c_str()); - break; + reporter->Warning("thread %s has not yet terminated ...", Name().c_str()); + fprintf(stderr, "warning: thread %s has not yet terminated ...", Name().c_str()); } usleep(1000); } - Finished(); - // One more message to make sure the current queue read operation unblocks. SendIn(new UnblockMessage(this), true); }