Bug 45868 - mod_mem_cache update of headers in cache object isn't atomic
Summary: mod_mem_cache update of headers in cache object isn't atomic
Status: RESOLVED LATER
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_cache (show other bugs)
Version: 2.2.8
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: MassUpdate
Depends on:
Blocks:
 
Reported: 2008-09-23 16:46 UTC by Brandon Lucia
Modified: 2018-11-07 21:08 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brandon Lucia 2008-09-23 16:46:32 UTC
I am using mod_mem_cache with the worker MPM.  Using a profiling tool for detecting certain interleavings between the code of concurrently executing threads, I have discovered that headers which actually end up being cached may have originated partially from 1 thread, and partially from another.  Specifically, look at the following code:

   mobj->req_hdrs = deep_table_copy(mobj->pool, r->headers_in);
   /* Precompute how much storage we need to hold the headers */
   headers_out = ap_cache_cacheable_hdrs_out(r->pool, r->headers_out,
                                             r->server);
   /* If not set in headers_out, set Content-Type */
   if (!apr_table_get(headers_out, "Content-Type")
       && r->content_type) {
       apr_table_setn(headers_out, "Content-Type",
                      ap_make_content_type(r, r->content_type)); 
   }
   headers_out = apr_table_overlay(r->pool, headers_out, r->err_headers_out);
   mobj->header_out = deep_table_copy(mobj->pool, headers_out);


Here, the mobj->req_hdrs are assigned to the deep_table_copy result, which is based on r->headers_in.  After a short while, mobj->header_out is assigned to the deep_table_copy of the headers_out object (which is computed from r->headers_out).  Under heavy load (~100 concurrent requests), while this is happening in one thread (T1, say), it can be (and likely is) happening concurrently in another (T2, say).  So:  between when T1 writes mobj->req_hdrs, and when T1 writes mobj->header_out, T2 is able to preempt T1, and write mobj->req_hdrs and mobj->header_out.  The sequence of events is as follows:

T1: Write mobj->req_hdrs
T2: Write mobj->req_hdrs
T2: Write mobj->header_out
T1: Write mobj->header_out

This results in mobj->req_hdrs being the version written by the request being processed in T1, and mobj->header_out being the version written by the request being processed in T2.  Depending on the nature of the requests being issued, this could result in an inconsistent pair of headers being stored in the cached object.
Comment 1 William A. Rowe Jr. 2018-11-07 21:08:47 UTC
Please help us to refine our list of open and current defects; this is a mass update of old and inactive Bugzilla reports which reflect user error, already resolved defects, and still-existing defects in httpd.

As repeatedly announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.x series of releases. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases. All reports older than 2.4.x have been updated to status RESOLVED/LATER; no further action is expected unless the report still applies to a current version of httpd.

If your report represented a question or confusion about how to use an httpd feature, an unexpected server behavior, problems building or installing httpd, or working with an external component (a third party module, browser etc.) we ask you to start by bringing your question to the User Support and Discussion mailing list, see [https://httpd.apache.org/lists.html#http-users] for details. Include a link to this Bugzilla report for completeness with your question.

If your report was clearly a defect in httpd or a feature request, we ask that you retest using a modern httpd release (2.4.33 or later) released in the past year. If it can be reproduced, please reopen this bug and change the Version field above to the httpd version you have reconfirmed with.

Your help in identifying defects or enhancements still applicable to the current httpd server software release is greatly appreciated.