Branch: Tag:

2011-06-09

2011-06-09 20:36:03 by Martin Stjernholm <mast@lysator.liu.se>

Avoid updating queue_time twice when try_again_later is used.

This could cause the queue_time calculation to bug out and return 503
(service unavailable) when Roxen.http_try_again or
Roxen.http_try_resume was used.

Rev: server/protocols/http.pike:1.639

2:   // Modified by Francesco Chemolli to add throttling capabilities.   // Copyright © 1996 - 2009, Roxen IS.    - constant cvs_version = "$Id: http.pike,v 1.638 2011/03/06 14:48:54 mast Exp $"; + constant cvs_version = "$Id: http.pike,v 1.639 2011/06/09 20:36:03 mast Exp $";   // #define REQUEST_DEBUG   #define MAGIC_ERROR   
2965:   }      // Execute the request. This is called from a handler thread. - void handle_request( ) + protected void handle_request_from_queue( )   {    if (mixed err = catch {    -  REQUEST_WERR("HTTP: handle_request()"); -  TIMER_START(handle_request); +  REQUEST_WERR("HTTP: handle_request_from_queue()");       int now = gethrtime();    queue_time = now - queue_time;
2979:    // "503 - server too busy" response..    int queue_timeout = conf->handler_queue_timeout;    if (queue_timeout && queue_time/1E6 > queue_timeout) { +  REQUEST_WERR (sprintf ("HTTP: Too long in queue (%d ms) - returning 503\n", +  queue_time));    file = Roxen.http_rxml_answer (conf->query ("503-message"),    this, 0, "text/html");    file->error = Protocols.HTTP.HTTP_UNAVAIL;
2990:    return;    }    +  handle_request(); +  +  }) { +  call_out (disconnect, 0); +  report_error("Internal server error: " + describe_backtrace(err)); +  } + } +  + void handle_request() + { +  if (mixed err = catch { +  +  REQUEST_WERR("HTTP: handle_request()"); +  TIMER_START(handle_request); +    #ifdef MAGIC_ERROR    if(prestate->old_error)    {
3026:       MARK_FD("HTTP handling request");    -  handle_time = now; +  handle_time = gethrtime();   #if constant(System.CPU_TIME_IS_THREAD_LOCAL)    handle_vtime = gethrvtime();   #endif
3615:    REQUEST_WERR("HTTP: Calling roxen.handle().");    queue_time = gethrtime();    queue_length = roxen.handle_queue_length(); -  roxen.handle(handle_request); +  roxen.handle(handle_request_from_queue);    })    {    report_error("Internal server error: " + describe_backtrace(err));