queso icon indicating copy to clipboard operation
queso copied to clipboard

Infinite recursion in queso_terminate_handler

Open briadam opened this issue 8 years ago • 3 comments

When running QUESO (through Dakota) in serial mode (MPI_Init not called) in GDB, it seems one can get into an infinite recursion with terminate_handler. I think what's happening is:

  • Uncaught exception is thrown, resulting in std::terminate calling queso_terminate_handler()
  • queso_terminate_handler() calls old_terminate_handler(), which in this case is NULL, which causes a seg fault that's not caught
  • Which causes queso_terminate_handler() to be called again.

Result in GDB is a call stack of significant length. I scrolled through about 10000 frames before quitting.

briadam avatar Jan 05 '17 20:01 briadam

For now, I'm working around this with:

diff --git a/queso/src/core/src/Environment.C b/queso/src/core/src/Environment.C
index 500ed27..a4e24ff 100644
--- a/queso/src/core/src/Environment.C
+++ b/queso/src/core/src/Environment.C
@@ -1735,10 +1735,10 @@ void queso_terminate_handler()
       // The system terminate_handler may do useful things like printing
       // uncaught exception information, or the user may have created
       // their own terminate handler that we want to call.
-      old_terminate_handler();
+      if (old_terminate_handler) old_terminate_handler();
     }
 #else
-  old_terminate_handler();
+  if (old_terminate_handler) old_terminate_handler();
 #endif
   exit(1);
 }

briadam avatar Jan 05 '17 20:01 briadam

Correction, that doesn't fix it. It seems whatever terminate_handler GDB registers is not NULL and is causing the recursion, so the workaround is to just not register queso_terminate_handler. I'll try to put together a test case "soon."

briadam avatar Jan 05 '17 20:01 briadam

Is the old terminate hander throwing an exception? A segfault shouldn't cause the terminate handler to be called unless you've got some other code that attaches a signal handler and calls the C++ terminate handler for it.

roystgnr avatar Jan 06 '17 18:01 roystgnr