Branch: Tag:

2007-09-12

2007-09-12 16:53:01 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Fixed potential refresh race in the protocol cache.

Rev: server/protocols/http.pike:1.531

2:   // Modified by Francesco Chemolli to add throttling capabilities.   // Copyright © 1996 - 2004, Roxen IS.    - constant cvs_version = "$Id: http.pike,v 1.530 2007/09/12 16:45:48 anders Exp $"; + constant cvs_version = "$Id: http.pike,v 1.531 2007/09/12 16:53:01 grubba Exp $";   // #define REQUEST_DEBUG   #define MAGIC_ERROR   
2587: Inside #if defined(RAM_CACHE)
   real_cookies = cookies = ~cookies;    }    -  int refresh; +  int(0..1) refresh;    if (cv[1]->refresh && (cv[1]->refresh <= predef::time(1))) { -  // We need to refresh the entry. -  refresh = 1 + predef::time(1) - cv[1]->refresh; -  m_delete(cv[1], "refresh"); -  misc->connection = "close"; +  // We might need to refresh the entry. +  // Note that we use the return value from m_delete() +  // to make sure we are free from races. +  if (refresh = m_delete(cv[1], "refresh")) { +  refresh = 1 + predef::time(1) - refresh;    } -  +  }       int code = file->error;    int len = sizeof(d);
2682: Inside #if defined(RAM_CACHE)
   cache_status["protcache"] = 1;       if (!refresh) { +  // No need to refresh the cached entry, so we just send it, +  // and are done.    TIMER_END(cache_lookup);    low_send_result(full_headers, d, sizeof(d));    return;
2709: Inside #if defined(RAM_CACHE)
   id->low_send_result(full_headers, d, sizeof(d));       my_fd = 0; +  misc->connection = "close";       MY_TRACE_ENTER (    sprintf("Entry in need of refresh (%d seconds past refresh)",