Fix Common Windows Segmentation Faults With Drupal
At Treehouse Agency, we often work with internal development teams, and enterprise software being what it is, they often run Windows. This has been the primary driver behind some of our technology choices (using Mercurial rather than Git on these sorts of projects) and it also occasionally necessitates some extra debugging when something doesn’t quite work right on Windows.
In work on a recent project, the client developers were using WampServer, but upon the site reaching a certain size, developers on Windows noted that their Apache processes were quitting after a cache clear. We debugged and tracked the errors down to occuring during CSS preprocessing. The Apache processes were segmentation faulting, resulting in an error dialog.
In an initial assessment of the problem, it appeared that others were having the same problem, such as in http://drupal.org/node/424136. We advised the developers to add a line to their settings.php to disable css preprocessing, like so:
‘preprocess_css’ => FALSE,
This worked fine for awhile, but then the same problem came back in a different situation. Developers on Windows began to see the same segmentation faults on the main Features administration page or when reverting all Features. This led me to the real cause of these segmentation faults - stack overflows. Both CSS preprocessing and Features reversion result in a number of recursive calls that will overflow a small stack, and therein lies a solution.
By default, Mac OS X allocates 8 megabytes of stack space for processes, while Windows allocates a much smaller amount (which looks to be closer to 1 megabyte.) By changing the Apache configuration to allocate the same 8 megabytes of stack space per Apache thread, developers on Windows no longer experienced segmentation faults when optimizing CSS files or when reverting Features.
In order to set the stack size back up to 8 megabytes, you need to set the
ThreadStackSize parameter in your Apache configuration files to
8388608. (The value is expressed in bytes.)
If this issue is affecting you on Windows, here are the two changes that you will need to make to your Windows configuration under WampServer.
In your main apache configuration file, uncomment the line that includes the httpd-mpm.conf file, like so:
And then in the httpd-mpm.conf file, add a line to set the stack size up to 8 MB (as it is on Mac and Linux Apache by default.) Specifically, add the third line in:
Once Apache is restarted, you should be free of segmentation faults (or at least you shouldn’t run into problems until your colleagues on Linux and Mac OS do.)