--------------------- PatchSet 6819 Date: 2008/02/14 21:46:38 Author: chtsanti Branch: async-calls Tag: (none) Log: Adding a machanism which in the case the current AsyncCall support it, do not abort imediatelly the squid but just aborts the current call. The mechanism uses C++ exceptions. Currently only AsyncJob related AsyncCalls can handle exceptions. Maybe not all the AsyncJobs are able to handle properly an exception.In this case they must implement the "abortOnException()" virtual method as follows: virtual bool abortOnException() {return true;}; Members: src/Debug.h:1.10.4.2->1.10.4.3 src/debug.cc:1.18.4.2->1.18.4.3 src/ICAP/AsyncJob.cc:1.3.4.12->1.3.4.13 src/ICAP/AsyncJob.h:1.3.14.10->1.3.14.11 Index: squid3/src/Debug.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Debug.h,v retrieving revision 1.10.4.2 retrieving revision 1.10.4.3 diff -u -r1.10.4.2 -r1.10.4.3 --- squid3/src/Debug.h 24 Jan 2008 03:45:15 -0000 1.10.4.2 +++ squid3/src/Debug.h 14 Feb 2008 21:46:38 -0000 1.10.4.3 @@ -1,5 +1,5 @@ /* - * $Id: Debug.h,v 1.10.4.2 2008/01/24 03:45:15 rousskov Exp $ + * $Id: Debug.h,v 1.10.4.3 2008/02/14 21:46:38 chtsanti Exp $ * * DEBUG: section 0 Debug Routines * AUTHOR: Harvest Derived @@ -52,6 +52,9 @@ #define assert(EX) ((EX)?((void)0):xassert("EX", __FILE__, __LINE__)) #endif +void WillCatchException(int debug_section, int debug_level, const char *who); +void WontCatchException(); + /* defined names for Debug Levels */ #define DBG_CRITICAL 0 /**< critical messages always shown when they occur */ #define DBG_IMPORTANT 1 /**< important messages always shown when their section is being checked */ Index: squid3/src/debug.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/debug.cc,v retrieving revision 1.18.4.2 retrieving revision 1.18.4.3 diff -u -r1.18.4.2 -r1.18.4.3 --- squid3/src/debug.cc 24 Jan 2008 03:45:21 -0000 1.18.4.2 +++ squid3/src/debug.cc 14 Feb 2008 21:46:38 -0000 1.18.4.3 @@ -1,5 +1,5 @@ /* - * $Id: debug.cc,v 1.18.4.2 2008/01/24 03:45:21 rousskov Exp $ + * $Id: debug.cc,v 1.18.4.3 2008/02/14 21:46:38 chtsanti Exp $ * * DEBUG: section 0 Debug Routines * AUTHOR: Harvest Derived @@ -36,10 +36,15 @@ #include "Debug.h" #include "SquidTime.h" #include +#include "TextException.h" int Debug::Levels[MAX_DEBUG_SECTIONS]; int Debug::level; +static bool AsyncCall_Handling_Exceptions = 0; +int TheCascadingAsserts = 0; +int TheSalvagedAsserts = 0; + static char *debug_log_file = NULL; static int Ctx_Lock = 0; static const char *debugLogTime(void); @@ -567,10 +572,39 @@ return buf; } +void WillCatchException(int debug_section, int debug_level, const char *who){ + if(AsyncCall_Handling_Exceptions) { + debugs(0, 0, "AsyncCall handling exceptions already enabled! The last caller is:" << who ); + abort(); + } + debugs(debug_section, debug_level, "The " << who << " will handle exceptions"); + AsyncCall_Handling_Exceptions = true; +} + +void WontCatchException(){ + AsyncCall_Handling_Exceptions = false; + TheCascadingAsserts = 0; +} + +#define MAX_CASCADING_ASSERTS 10 void xassert(const char *msg, const char *file, int line) { + + if (TheCascadingAsserts < MAX_CASCADING_ASSERTS && AsyncCall_Handling_Exceptions) { + TheCascadingAsserts++; + TheSalvagedAsserts++; + debugs(0, 0, "assertion failed: " << file << ":" << line << ": \"" << msg << "\". Trying to survive. Salvaged assertions: " << TheSalvagedAsserts); + + AsyncCall_Handling_Exceptions = false; + + throw TextException(msg, file, line); + } + debugs(0, 0, "assertion failed: " << file << ":" << line << ": \"" << msg << "\""); + if(TheCascadingAsserts >= MAX_CASCADING_ASSERTS) + debugs(0, 0, "I am dying after " << TheCascadingAsserts << "cascading assertions!" ); + if (!shutting_down) abort(); } Index: squid3/src/ICAP/AsyncJob.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/AsyncJob.cc,v retrieving revision 1.3.4.12 retrieving revision 1.3.4.13 diff -u -r1.3.4.12 -r1.3.4.13 --- squid3/src/ICAP/AsyncJob.cc 24 Jan 2008 21:29:15 -0000 1.3.4.12 +++ squid3/src/ICAP/AsyncJob.cc 14 Feb 2008 21:46:39 -0000 1.3.4.13 @@ -119,6 +119,9 @@ { // we must be called asynchronously and hence, the caller must lock us Must(cbdataReferenceValid(toCbdata())); + + if(abortOnException()) + abort(); mustStop("exception"); } @@ -198,8 +201,10 @@ job->callStart(call); try { + WillCatchException(call.debugSection, 3, call.name); doDial(); - } + WontCatchException(); + } catch (const TextException &e) { debugs(call.debugSection, 3, HERE << call.name << " threw exception: " << e.message); Index: squid3/src/ICAP/AsyncJob.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/AsyncJob.h,v retrieving revision 1.3.14.10 retrieving revision 1.3.14.11 diff -u -r1.3.14.10 -r1.3.14.11 --- squid3/src/ICAP/AsyncJob.h 24 Jan 2008 21:29:15 -0000 1.3.14.10 +++ squid3/src/ICAP/AsyncJob.h 14 Feb 2008 21:46:39 -0000 1.3.14.11 @@ -3,7 +3,7 @@ /* - * $Id: AsyncJob.h,v 1.3.14.10 2008/01/24 21:29:15 rousskov Exp $ + * $Id: AsyncJob.h,v 1.3.14.11 2008/02/14 21:46:39 chtsanti Exp $ */ #ifndef SQUID_ASYNC_JOB_H @@ -63,6 +63,7 @@ void callStart(AsyncCall &call); virtual void callException(const TextException &e); virtual void callEnd(); + virtual bool abortOnException() {return false;}; protected: const char *stopReason; // reason for forcing done() to be true