ColdFusion stopped = Apache unresponsive

In my local development set up, I sometimes don’t want to have ColdFusion running as I’ll be working on something that’s just HTML, JavaScript or using another language like PHP (don’t tell no one!). Everytime I tried this, Apache would crawl to a halt when requesting non-ColdFusion files (css, html, js, php etc…). If I started ColdFusion up, everything worked perfectly, maybe life is just better with ColdFusion always on ;)

Delving into the Apache HTTPD configuration file, I couldn’t spot anything out of place. The “AddHandler jrun-handler” looked correct as it was only specifying ColdFusion extensions. As a guess I decided to restrict things a little further by using the “Files” tag. Setting this with a regular expression to match files ending with the required extensions did the trick.

# ---COLDFUSION---

# Load the module
<IfModule !jrun_module>
  LoadModule jrun_module "C:/JRun4/lib/wsconfig/1/mod_jrun22.so"
</IfModule>

# Configure the JRun module
<IfModule jrun_module>
  # Restrict to ColdFusion files only.
  <Files ~ "\.(cfm|cfml|cfc|cfr|cfswf)$">
    JRunConfig Verbose false
    JRunConfig Apialloc false
    JRunConfig Ignoresuffixmap false
    JRunConfig Serverstore "C:/JRun4/lib/wsconfig/1/jrunserver.store"
    JRunConfig Bootstrap 127.0.0.1:51002
    AddHandler jrun-handler .cfm .cfml .cfc .cfr .cfswf
  </Files>
</IfModule>

I haven’t really figured out why this was happening, but at least there’s a way to stop it.  Would be useful for anyone who puts up a HTML page during maintenance where ColdFusion would need to be stopped.

Hope this helps anyone puzzled with the same issue. It’d be great if it became part of the default configuration that ColdFusion sets when hooking it up to Apache.

Windows + Apache + mod_fcgid + complex Active Directory = 70008 Partial Results

Introduction

I like to run PHP under Apache via FastCGI, it feels performant enough and has the benefit of not bringing down Apache if PHP crashes (as can happen when using PHP as a module). In my job I had set this up and it was working beautifully, but little did I know what the future held…

One by one, as my servers were restarted for various reasons (Updates, changes etc…) they all threw a wobbly when starting up, saying that:

Wrapper C:/Apache2/php/php-cgi.exe cannot be accessed: (70008)Partial results are valid but processing is incomplete

Investigation

So the game was afoot… First thought was a Windows Update had broken something but this didn’t seem to be the case. A search of the Internet didn’t found many others who had hit the same problem, I would have expected more complaints if Microsoft had released an update that broken Apache / FastCGI. Another thought was the Virus scanner, but that hadn’t received any major updates apart from definition packages.

Had permissions changed? Nope. I even tried changing permissions to be totally relaxed and the same error would appear. Restricting permissions on purpose provided the expected error of being unable to access the executable. At this point the issue had spread to every work server and client I had access to, was I cursed?

I then decided to try testing the Apache set up on a fresh VM of Windows XP (no network connection, no extra software, no virus scanner, fully patched). It worked like a dream, so I start blaming the Virus scanner again but after a few more tests (adding certain executables to be ignored, disabling the scanner etc…) I felt it wasn’t to blame.

Tracking down the villain, recompiling mod_fcgid

My only hope, after fruitless searches of the Internet, appeared to be recompiling the module to find the root cause. Now I’m purely a ColdFusion, PHP, JavaScript, HTML kinda guy… The last time I had to compile something was back in the days of Turbo Pascal. Without really knowing what I was doing, I managed to stumble my way into setting up the right development environment for recompiling mod_fcgid. Here are the rough steps I took:

  1. Downloaded the latest version of Apache Httpd VC9 (Visual C++ 2008) from ApacheLounge. I’ve been using this version as I find it performs a bit better than the VC6 version the Apache Foundation offers and upgrading is easier when just dealing with a zip file ;)
  2. I extracted this to “c:\Apache2″, as I’ll reference these files further down.
  3. Installed TortoiseSVN and checked out a copy of the mod_fcgid source code.
  4. Installed Microsoft Visual C++ 2008 Express SP1. It’s free thankfully but did take a while to download everything it needed.
  5. Before running anything else, right click on “My Computer” and select “Properties > Advanced > Environmental Variables” and add a new System variable called “APACHE2_HOME” set to “c:\Apache2″.
  6. Run Visual C++ 2008 Express
    1. Open a project and select the mod_fcgid.dsw file from your checkout of the source.
    2. It mumbled something about updating the file so I just agreed.
    3. Should then see a list of the files in the “Solution Explorer”.
    4. Right clicked on “mod_fcgid” under the “Solution Explorer” and selected “Properties”.
      1. In “Configuration Properties > C/C++ > General”, I added the following directories to the “Additional Include Directories” setting, keeping in mind that you may have different paths, depending on where you extracted Apache.
        C:\Apache2\lib,C:\Apache2\include

        Additional Include Directories

        Additional Include Directories

      2. Under “Configuration Properties > Linker > Input > Additional Dependencies” I added the following.
        c:\Apache2\lib\*.lib

        Additional Dependencies

    5. Now comes the bit where I didn’t really know what I was doing. I wanted the mod_fcgid.so created from the source but only found one way of getting it to spit it out. There’s probably another way but I couldn’t spot it.
    6. Click on the “Build” menu and select “Batch Build…”.
      1. You should be presented with a dialogue box with two items listed. Check the “Build” box for the one with “Configuration” set to “Release”.
      2. Click the “Build” button.

      Building mod_fcgid.so

    7. Fingers crossed you’ll see some activity of the module being built.
    8. Once it’s finished, check out the folder “mod_fcgid\modules\fcgid\Release” for “mod_fcgid.so”.

Code at issue

With that all working, now was the time to hunt down that part which was throwing the error. I started with a search for the string “cannot be accessed”, which showed up in “fcgid_conf.c” under the “missing_file_msg” function. Not a bad start, so a quick search for what was calling “missing_file_msg” showed up a prime suspect under “set_wrapper_config” that looks like this:

    /* Does the wrapper exist? */
    if ((rv = apr_stat(&finfo, path, APR_FINFO_NORM,
                       cmd->temp_pool)) != APR_SUCCESS) {
        return missing_file_msg(cmd->pool, "Wrapper", path, rv);
    }

Commenting out the “return” line, recompiled and tested… It worked! So what the smeg was going on?

The culprit

Let me introduce you to APR_FINFO_NORM as best I can. I don’t know him that well, we’ve only just met, but after first impressions I think I’ve got a rough idea of the bloke. APR_FINFO_NORM basically asks the Apache Portable Runtime to get the full information about a file, in my case php-cgi.exe, including permissions. Shouldn’t be a problem and a very sensible thing to check, since if Apache Httpd didn’t have access to php-cgi.exe it wouldn’t be able to serve those lovely PHP files.

For the majority of users and installations, this isn’t a problem. APR_FINFO_NORM returns the information successfully (APR_SUCCESS) and Apache Httpd smiles, nods and carries on. However, if the computer is a member of Microsoft Active Directory and that AD forest is complex or large enough, you’ll hit an issue. Thanks to Microsoft, the API call that they provided called GetEffectiveRightsFromACL that “apr_stat” is using, can’t cope.

This causes “apr_stat” to return an APR_INCOMPLETE and in turn, Apache Httpd thinks it hasn’t got access and throws the (70008)Partial Results error, since it only got a partial set of permission results… I guess.

Check out the bug that has been logged for mod_fcgid and another for the “apr_stat” issue itself that’s the root cause.

Solutions

Blimey, that was a bit of sluething! Don’t worry though, as I proved above, there are ways around this until it’s resolved.

Option 1: Patch mod_fcgid

Patched code

If you look at the bug record that has been filed for mod_fcgid, you’ll see that a patch has been attached. This changes the code to avoid checking for permissions, which will obviously cause problems if Apache Httpd hasn’t got permissions, but otherwise solves our problem completely and still at least checks that the file exists. Of course this does mean you’ll have to recompile the module yourself.

    /* get only require details file inode + device info */
    if ((rv = apr_stat(&finfo, path, APR_FINFO_IDENT,
                       cmd->temp_pool)) != APR_SUCCESS) {
        return missing_file_msg(cmd->pool, "Wrapper", path, rv);
    }

Option 2: Change permissions on the FastCGI target

Security settings

In my case this is php-cgi.exe, but obviously there are plenty of other things that can sit behind FastCGI. Here you’ll need to make sure “apr_stat” doesn’t need to check Active Directory.

  • Edit the permissions of php-cgi.exe, or whatever you’re using with FastCGI.
  • Prevent it from inheriting permissions from above.
  • Remove any users and groups that aren’t local to the server, so anything that is from the Active Directory.
  • Also, check the local groups! You’ll might find Active Directory users / groups have been added to the local computers groups. If this is the case, they’ll need to be removed from the permissions.
  • In my case, I ended up with just the local SYSTEM account and the local Administrator account. If you run Apache as another user, they’ll have to have access as well… unless they’re from Active Directory, in which case “This is not the solution you are looking for” (Waves hand).
  • Start up Apache and hopefully it’ll work perfectly, error message banished.

Again, this solution is great unless you run Apache as an Active Directory user for some reason.

Option 3: Don’t let the server be a member of Active Directory

Extremely similar to the above, but taken a step further. If the server isn’t a member of the Active Directory, then none of those users or groups will have permissions. No need for “apr_stat” to go asking questions about them ;)

Option 4: Wait until Apache fix the code

Depending on what you’re using mod_fcgid for, there are usually alternative methods available. For example, PHP can be run as an Apache module. This may not be ideal, but if any of the above aren’t an option for you, needs must.

Help promote the problems

By the looks of things, not many people have hit this issue when you search for the mysterious “(70008)Partial Results” error. But those who are affected will tend to be people in large organisations with those big complex Active Directories. Surely (I know, don’t call you Shirley) that’s the kind of large environment and organisation that you’d want Apache to have a good reputation?

If your affected, please help vote up the bugs, comment about how it has affected you or just state how you’d like to see this fixed.

  • mod_fcgid bug 51020: Apache/mod_fcgid.so does not start in complex Active Directory forest
  • Apache Portable Runtime bug 51560: apr_stat for APR_FINFO_NORM using GetEffectiveRightsFromAcl does not work in complex Active Directory forest
  • mod_xsendfile issue 8: Also affected by the same APR bug, but during operation (unable to access files) rather than preventing start up.

Ideally the Apache Portable Runtime (APR) will be fixed, solving the problem for any other code which uses a APR_FINFO_NORM with “apr_stat”. But I’ve no idea what alternative methods they could use (something called “AuthZ APIs”?) and if that’d be available in all the Windows environments they want to support. Anyway, hopefully this will prove helpful to someone ;)

CFTracker, CFFocus, thgFlow, my own blog…. plate full enough?

Eyes bigger than your belly, as the saying goes.  Guess that must be me at the moment as it seems that I’ve got a bit more than I can currently handle.

CFTracker

My ColdFusion / Railo / OpenBD server monitor project has been left in a dusty corner for a while now, starved on the attention it deserves.  I’m going to try my hardest to kick it back into some form of activity as I know there are people out there who actually find it useful ;)  Here’s a list of what’s going on and planned for the project.

  • Just switched hosting providers (big mad thanks to BigMadKev for hosting until recently and thanks to HostMediaUK for the hosting it now).
  • Planning on switching to Mura for the site.
  • Looking for developers to join me as a team to work on the project.  Any of the following skills would useful:
    • Java (logging, application server knowledge, remote methods, scheduling, good Java experience)
    • ColdFusion skills (especially FW/1 or object orientated talents).
    • Graphic / UI designs (usability improvements, new design / colour scheme, logo refresh?)
  • Provide access to the “development” versions of the CFTracker Java library for people to try out.

CFFocus

Again this is something that I haven’t been finding enough time for lately.  The site hasn’t been getting the weekly updates it was suppose to.  Currently working on a little web application that’ll help construct the updates and hopefully get things back to where they should be.

thgFlow

I’ve fallen for another type of source control called Mercurial.  Feels a lot nicer to use than git, especially on Windows and the GUI support for it.  I’m a big fan of a certain branching model that is supported in git via gitflow and wanted to try to get support added for it in TortoiseHg, based on the work of hgflow.  Probably more than I should be taking on but this is something that could prove really useful to my real job.

My poor blog

It’s been starved for attention more than most things.  I’m going to try and share more of my development experiences as I go along and encounter things.  Don’t except epic blog posting on the scale of Ben Nadel though as I still don’t understand where he finds the time (machine?) to do all those posts.

Expect posts about my adventures trying to do some Python development with thgFlow, the odd ColdFusion post when I encounter something I’d like to share and any other waffle.  Of course that’s all between juggling my job and life with 3 kids :P

New ColdFusion Community News site

Following on from my previous post, but expanding in scope.  I’m currently putting together a site (with a couple of volunteers) to try and cover activity within the ColdFusion community.  Obvisouly this is no small task so I’d like to enlist some help.

I’d like the site to cover everything ColdFusion related.  Engines, editors, projects and products alike, whatever license they may adhere to.  Any content on the site will hopefully be unbiased and trying not to lean too far to any side of the community.

Survey

Help me out and provide some feedback on what the site should cover.

http://spreadsheets.google.com/a/yougeezer.co.uk/viewform?formkey=dGhNcmxCYTdWcHJ4RFlpOEliOXBJR2c6MQ

Join the team

If you’ve got some spare time and wouldn’t mind monitoring an aspect of the community and reporting back to the planned site, let me know.

http://misterdai.wordpress.com/contact/

Where’s the site?

Thanks for asking.  We’re currently preparing everything as I’d like more things in place before it goes public.  Major things like hosting, domain name and CMS have been set up.  Just need to see who wants in, what you lot want on it and getting the design right.

Wish me luck :)

ColdFusion Open Source Update and beyond…

As some of you may already know, Brian Rinaldi has recently announced that he’s ending his “ColdFusion Open Source Update” series of blog posts. Thankfully it was for all the right reasons, being the fact that there is too much going on in the CFML Open Source community for Brian to dedicate enough time towards.

I personally found the updates were extremely useful for keeping up with what was going on with open source projects. Later I also gained from my projects being mentioned in the updates, spreading the knowledge of them and providing a nice source of potential users.

What do we do now?

There are still ways to keep up with CFML based open source. RIAForge has a subscription, as Ray Camden has pointed out.

Pull our thumbs out?

Personally I think we, as a community, should pull our thumbs out. Brian did a fantastic job, but maybe if some of us got together we could produce something even better. We could continue the series of posts, but with multiple people working towards it the time required would decrease for each of us. Or we could take the chance to create a site dedicated to CFML open source news that could also provide useful information to aid in all the work maintaining a project requires.

To that end I’ve created a Google Group to discuss this, or even just chat about CFML open source in general. Feel free to join me there and we’ll see if anything develops out of it.

http://groups.google.com/group/cfml-open-source

Follow

Get every new post delivered to your Inbox.