Branch: Tag:

2006-12-14

2006-12-14 12:55:03 by Marcus Wellhardh <wellhard@roxen.com>

Packport from 4.6: ABS should now be able to detect hung handler threads.

Rev: server/base_server/roxen.pike:1.949

6:   // Per Hedbor, Henrik Grubbström, Pontus Hagland, David Hedbor and others.   // ABS and suicide systems contributed freely by Francesco Chemolli    - constant cvs_version="$Id: roxen.pike,v 1.948 2006/11/23 13:07:35 mast Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.949 2006/12/14 12:55:03 wellhard Exp $";      //! @appears roxen   //!
2672: Inside #if undefined(__NT__)
     #ifndef __NT__   static int abs_started; + static int handlers_alive;    - void restart_if_stuck (int force) - //! @note - //! Must be called from the backend thread due to Linux peculiarities. + static void low_engage_abs()   { -  remove_call_out(restart_if_stuck); -  if (!(query("abs_engage") || force)) -  return; -  if(!abs_started) -  { -  abs_started = 1; -  report_debug("Anti-Block System Enabled.\n"); +  report_debug("**** %s: ABS exiting roxen!\n\n", +  ctime(time()) - "\n"); +  _exit(1); // It might not quit correctly otherwise, if it's +  // locked up   } -  call_out (restart_if_stuck,10); - // werror("call_out_info %O\n", filter(call_out_info(), lambda(array a) { - // return a[2] == restart_if_stuck; })); -  signal(signum("SIGALRM"), -  lambda( int n ) { +  + static void engage_abs(int n) + {    if (!query("abs_engage")) {    abs_started = 0;    report_debug("Anti-Block System Disabled.\n");
2700: Inside #if undefined(__NT__)
   "Trying to dump backlog: \n",    ctime(time()) - "\n",    query("abs_timeout")); +  // Paranoia exit in case describe_all_threads below hangs. +  signal(signum("SIGALRM"), low_engage_abs); +  int t = alarm(20);    catch {    // Catch for paranoia reasons.    describe_all_threads();    }; -  report_debug("**** %s: ABS exiting roxen!\n\n", -  ctime(time())); -  _exit(1); // It might now quit correctly otherwise, if it's -  // locked up -  }); +  low_engage_abs(); + } +  + void restart_if_stuck (int force) + //! @note + //! Must be called from the backend thread due to Linux peculiarities. + { +  remove_call_out(restart_if_stuck); +  if (!(query("abs_engage") || force)) +  return; +  if(!abs_started) +  { +  abs_started = 1; +  handlers_alive = time(1); +  report_debug("Anti-Block System Enabled.\n"); +  } +  call_out (restart_if_stuck,10); + // werror("call_out_info %O\n", filter(call_out_info(), lambda(array a) { + // return a[2] == restart_if_stuck; })); +  signal(signum("SIGALRM"), engage_abs);    int t = alarm (60*query("abs_timeout")+20);    // werror("alarm: %d seconds left, set to %d\n", t, 60*query("abs_timeout")+20); -  +  if ((time(1) - handlers_alive) > 60*query("abs_timeout")) { +  // The handler installed below hasn't run. +  report_debug("**** %s: ABS: Handlers are dead!\n", +  ctime(time()) - "\n"); +  engage_abs(0);    } -  +  handle(lambda() { handlers_alive = time(1); }); + }   #endif      #if constant(ROXEN_MYSQL_SUPPORTS_UNICODE)