Bug 50559 - Memory leak on long lines, leading to complete system freeze
Summary: Memory leak on long lines, leading to complete system freeze
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_substitute (show other bugs)
Version: 2.5-HEAD
Hardware: PC All
: P2 blocker (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2011-01-07 08:08 UTC by Marc Stern
Modified: 2012-02-26 17:09 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Stern 2011-01-07 08:08:48 UTC
It seems that there is a finite memory leak, that is it does not increase indefinitely, but much too high any way. I managed to reproduce the problem on a low scale, but, when this happen in production (Linux), processes memory increases up to several GB, knocking down the complete OS (kernel not able to react because od too much swap).

This description is valid for Windows/Unix, but the measures are the scaled down Windows ones.
Here it is, in 3 steps:
 - Almost empty config, only mod_substitue loaded.
 - Start the server with "httpd -X" (for the measurements).
 - The initial memory size of the process is 3 MB.

Test 1:
I create a text file containing a very long line (250,000 char) containing (each) 32 times the string "xxxx" (with the quotes).
I add the directive
   Substitute  "s`(?<=\")xxxx`-xxxx`i"
On the first request, the memory increase up to 3.5 MB - no problems.
I resend the same request several hundred times (sequentially) and the memory does not increase.

Test 2:
I add, after the previous substitute, the directive
   Substitute  "s`zzzzzzzzzzzz`yyy`i"
The text file does not contain the string zzzzzz, so the rule never matches.
On the first request, the memory increase up to 20 MB - this definitely looks like a bug ...
I resend the same request several hundred times (sequentially) and the memory does not increase.

Test 3:
Same as test 2, but I copy the line in the text file a second time (on a new line).
On the first request, the memory increase up to 20 MB - as previously.
I resend the same request several hundred times (sequentially) and the memory increases on each request.
It stabilizes around 55 MB.
If I add the line a third time, it goes up to 75 MB.
Comment 1 Stefan Fritsch 2011-03-09 17:18:11 UTC
The memory usage basically grows quadratically with the line length and with the number of substitutions per line. This sucks.

If appropriate for your patterns, you can maybe work around this by using the 'q' flag (see the docs). If there is only one Substitute pattern, the 'q' flag is always enabled, which is consistent with the behavior you observed.
Comment 2 William A. Rowe Jr. 2011-03-09 17:35:28 UTC
It would be interesting to compare to the apache 2.3.11-beta using mod_sed,
and compare the memory footprints.  See;

http://httpd.apache.org/docs/trunk/mod/mod_sed.html
Comment 3 Stefan Fritsch 2011-09-26 20:11:17 UTC
Fixed in trunk in r1176019
Comment 4 Stefan Fritsch 2012-02-26 17:09:44 UTC
fixed in 2.4.1