Steven Erat's Blog
 
 
Viewing By Entry
 
 

TalkingTree  Workaround for a cached File Not Found error message

 

Under unusual circumstances ColdFusion MX 7 server may cache a File Not Found (404 Status Code) error for a template and continue to return the error even when the expected template file resides in the proper location.

For a short reproducible case, create page hello.cfm with the text Hello and browse it. You'll see the page successfully completes. Rename the file to anything else, perhaps hello2.cfm, and browse to the original page hello.cfm again. Assuming that the CF Administrator setting for Missing Template Handler is not configured, you will receive a File Not Found error like this:

File not found: /hello.cfm
...

coldfusion.runtime.TemplateNotFoundException: File not found: /hello.cfm
   at coldfusion.filter.PathFilter.invoke(PathFilter.java:83)
   at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:69)
   at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:52)
   ...

At this point, the ColdFusion server is doing the right thing. Now to demonstrate the improper caching of the File Not Found error message, rename the hello2.cfm file back to the original file name hello.cfm. When you browse the hello.cfm file again, you will continue to see the error message even though the file is in the correct location with the original name.

This behavior will occur even when the settings Trusted Cache and Save Cache Files are turned off.

To workaround the problem in ColdFusion MX 7, create a template that uses the Admin API to clear the Template Cache. The method is called clearTrustedCache(), but this is just a slight misnomer as the Template Cache is cleared. Then configure this template as the Missing Template Handler in the ColdFusion Administrator Settings page. For usefulness, provide the name of the missing file and a link to try the page again, and add any other handling behavior you think might be pretty or appropriate.

An example of what the Missing Template Handler might look like is the following:

<!--- Clear the Trusted or Template Cache for ColdFusion MX 7.x --->
<cflock name="clearTrustedCacheLock" type="EXCLUSIVE" timeout="5" throwontimeout="No">
   <cfscript>
      request.CFADMIN_PASSWORD = "admin";
      request.adminObj = createObject("Component", "cfide.adminapi.administrator");
      request.adminObj.login(request.CFADMIN_PASSWORD);
      request.runtimeObj = createObject("component", "cfide.adminapi.runtime");
      request.runtimeObj.clearTrustedCache();
   </cfscript>
</cflock>
<!--- Provide a friendly file not found error message here --->
<cfoutput>
#error.message#<br/>
<a href="#cgi.script_name#">Try again</a>
</cfoutput>

 


Comments

One real world scenario where the cached 404 File Not Found message continues to be served is when serving content from a UNC share an interruption occurs on the network. When CF can't access the remote file it reports a 404, and when the content is available CF will continue serving the 404 unless this blog entry's workaround is used.

See this article for how to serve content over a UNC path:
http://www.talkingtree.com/blog/index.cfm/2005/7/2...


Thanks for this info - we're using it in our Test environment, with a scenario just like the example you used. We were surprised to find any caching going on when TrustedCache was turned off.

So clearTrustedCache actually clears the TemplateCache. In CFMX 7, what distinction is there between TrustedCache and TemplaceCache? s

thanks


The Trusted Cache setting just says weather or not to trust what is in the Template Cache. In this context, there is only one cache being referenced. The Trusted Cache setting would be better named something like "Trust the Template Cache", and maybe it would be clearer.

The server setting for trusted cache simply tells the server to either always check to see if the timestamp of every template has changed or to never check the the timestamps. If the setting is enabled, ColdFusion never checks the timestamps and it accepts that the templates it has in memory (in cache) are to be used to handle requests.

The template cache setting is how many cfm/cfc templates are held in memory and guaranteed to not be garbage collected (using a Last Recently Used, LRU, caching model to bump old templates out when the cache is full and new templates try to get in).

The problem in this File Not Found issue described here is that timestamp on the file never changes, although for a moment the file wasn't available and the generated HTML corresponding to the 404 error was put in memory. When the file is available again, ColdFusion sees that the timestamp *still has not* changed, so ColdFusion never re-reads the template file and just keeps serving the cached 404 message.

Since in the example the timestamps on the cfm files never change, the Trusted Cache setting has no relevance and the server executes the template version it has in memory in theTemplate Cache.


Thanks for the explanation. I was thinking TrustedCache might be a setting and not a separate entity. And I see how this caching issue is really an artifact of doing a rename/rename on the file.

Interestingly, though, this happens even when the 'Maximum number of cached templates' is set to zero. (CFMX v7.0.1 CHF2 on Solaris 9). I would have thought setting that to zero would force no caching.

Could you elaborate on how the TemplateCache works?

thanks


Like many other settings parameters, zero sometimes means infinity, not actually zero :)


Thanks .. I think :-)

If that's a Zen koan then to solve it I have to not-think about it, right?


I'm having this same issue. I've tried clearing the Template Cache through the administrator with no success. I also tried using the sample Missing Template Handler - but when I specify that page as the handler through the CF Administrator, it doesn't seem to do anything and if I go directly to that page I get the error below. However, I'm not familiar with the Admin API...

Error from accessing the Missing Template Handler directly:
The string "COOKIE.CFAUTHORIZATION_meded-db" is not a valid ColdFusion variable name.
Valid variable names must start with a letter, and can only contain letter, numbers, and underscores.

The error occurred in C:\blackstone_updates\cfusion\wwwroot\CFIDE\adminapi\administrator.cfc: line 106

-1 : Unable to display error's location in a CFML template


Thanks any assistance anyone can provide!


How would I go by setting up a Missing Template Handler on a CF MX7 server where I am set up as a seperate instance with my own admin console. I dont have access to the C: of the servers, or would I have to get the admins to add the Missing Template Handler cfm file on the C: drive?


There's not enough information to understand your inquiry. It sound as though you have an extra ColdFusion instance devoted for your usage and that you do not have access to the C: drive. Having access to C: drive root doesn't matter, but I assume that you must have write permission to the document root. Create a template there and then simply configure it as the missing template handler in the CFAdmin. I assume that if you have your own instance that you have access to the CFAdmin for that instance. On the CFAdmin "Server Settings" page, read the instructions below the field for Missing Template Handler, and you could find more help by clicking on the ? icon in the upper right.


I'm having a problem that seems to be the same; however, this script doesn't solve the problem. I had a Oracle stored procedure changed and it was temporarily in a state of 'invalid' when it was referenced through the site. After having him get back and fix it and getting it to the 'compiled' state, CFMX never rechecked the stored procedure, just simply posted back the original error message.

While this sounds more like a flaw in the design, there must be some way, other than restarting the service, to clear this error cache? Maybe a way to restart the JDBC? I don't know.

System: SuSE Enterprise Linux server 9
J2EE: Jrun 4
App: CFMX7
JVM: 1.4.2_03-b02
DB: Oracle 10


I'm having a problem that seems to be the same; however, this script doesn't solve the problem. I had a Oracle stored procedure changed and it was temporarily in a state of 'invalid' when it was referenced through the site. After having him get back and fix it and getting it to the 'compiled' state, CFMX never rechecked the stored procedure, just simply posted back the original error message.

While this sounds more like a flaw in the design, there must be some way, other than restarting the service, to clear this error cache? Maybe a way to restart the JDBC? I don't know.

System: SuSE Enterprise Linux server 9
J2EE: Jrun 4
App: CFMX7
JVM: 1.4.2_03-b02
DB: Oracle 10


I recall something like that once. After executing a stored procedure once, if the procedure is recompiled on the database ColdFusion will continue using the first one and not detect the new procedure. I know this will happen when connection pooling is on. Using a new datasource definition or not using connection pool will circumvent the problem (but are not very elegant workarounds).

I'll keep this in mind and post back if I turn up anything useful.


Adobe have said this is not a bug that they have been able to replicate themselves, so no bug fix is on the cards. Is there a specific set up or configuration that we're all using that causes this "bug" to appear?

I'm using a 2-server IIS cluster (NLB, sticky session) with templates stored on a file server (on a 3rd machine).

Thanks. Gary.


Gary, this is a bug (I am in Adobe CF support). The number is 58961. To reiterate in brief, the problem is that when a file is not accessible temporarily due to an OS or network problem, ColdFusion will report a 404 error, but when that file becomes avaiable again (network issue resolved) ColdFusion will continue to cache the 404 error.


Steven, how can I tell if that's the cause of our 404 error? Assuming it is, can you say when a fix will be made available please? Thanks for your time and quick reply.


Well, perhaps you could request a static html file in the same location as the remote cfm file to see if IIS can serve it. This is an IIS/network test that excludes ColdFusion. If the html page wont serve, then take the steps to address it. If html does work but cfm does not (404), then confirm you are running ColdFusion as a user account that has permission to access the network. If so, then test clearing the template cache by clicking the appropriate button in the CF Admin Caching page. Does clearing the template cache resolve the problem?


Steven, we have a mix of cfm and html files and have never experienced a 404 with static html files. CF is running under a domain account and has full read/write access to the entire directory structure. The "clear template cache" button temporarily fixes the 404 when we get them... until another cfm file suddenly reports a 404. We have 2 servers in a cluster and when one gets a 404 on a specific file the other server will happily serve the "missing" file correctly.

As you stated earlier, re-saving a file to update the timestamp also fixes the problem for the file in question.

What we can't detect is what the problem was at the time CF/JRun thought there was a network/file error. We haven't experienced other apps/services or Windows in general suggesting there is a file problem. Will the fix be part of 7.0.2? Thanks.


We are battling with this same issue, currently. Opening a file and resaving always fixes the issue. However, we are running on CFMX 6.1 and apparently the Component cfide.adminapi.administrator doesn't exist in 6.1.

Does anyone know of an equivalent workaround in 6.1? PLEASE!!!

Thanks,
Matt


For CFMX 6.1 the ServiceFactory method could be used (although directly accessing ServiceFactory is officially unsupported for development purposes, but as a workaround for this problem there should be no harm). The CFMX 7 Admin API is simply a supported wrapper to the ServiceFactory.

Touching the file (and thus changing the file timestamp) causes ColdFusion to reread the file because unless the Trusted Cache checkbox ColdFusion will always reload/recompile a cfm source file if it finds that the date has changed.


The bug for cached file not found was fixed in CFMX 7.02.


I think I'm having this exact problem on my dev machine. Unfortunately, I'm having the problem trying to login in to the administrator so the error message I'm seeing is:

Could not find the ColdFusion Component CFIDE.adminapi.administrator.

I Tried your code, but as you may have guessed it didn't solve the issue. Any ideas?


Jeff,

The ColdFusion Administrator has a ColdFusion mapping for /CFIDE defined in cf_root/lib/neo-runtime.xml. Make sure the mapping points to the right physical location for the actual CFIDE directory.


Steven

That was the solution to my problem. I stumbled onto it sometime over the weekend. Much Thanks!


 

 

Calendar

 
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Search This Site

 
This is an exact search only

About This Site

 
I live west of Boston and used to work at Adobe with ColdFusion and Flex, specializing in Unix & Linux. I recently graduated from CDIA in Pro Digital Photography. Curious about my banner image?

More about me

Recent Entries

 
Christmas Eve Service makes F..
How To Filter by File Type in..
Perspective on ColdFusion's B..
Power Mac G5: The lights are ..
My Application to CDIABU in R..

Recent Comments

 
Posted By Andy Allan:
Fantastic work Steve.

Posted By charlie arehart:
Oh wow, awesome to hear that the relative quiet was an imposed one, and that the gag order has been lifted. Now I'm really excited to hear what may co ...

Posted By Steven Erat:
Thanks for your encouragement Charlie. I have to say that even though I'm trying to be positive and use this time to improve my web skills, most of t ...

recently played

 
Snap Judgments
by WNYC, New York Public Radio
on On The Media
On The Media, WNYC, New York Public Radio

now playing, a plug-in for itunes

Categories

 
RSS Adobe (31)
RSS Bicycling (9)
RSS Blogging (37)
RSS Books (13)
RSS Breeze (12)
RSS CFMX Podcasts (10)
RSS ColdFusion (420)
RSS Computer Technology (50)
RSS Events (25)
RSS Flash (3)
RSS Flex (18)
RSS Gadgets (10)
RSS HiTech Industry (16)
RSS Java (25)
RSS Learning (57)
RSS Linux (70)
RSS Mac OS X (22)
RSS Macromedia (28)
RSS Meetup (34)
RSS New England (62)
RSS Odds & Ends (25)
RSS Outdoors (32)
RSS Personal (29)
RSS Photography (109)
RSS Photoshop (29)
RSS Podcasts (18)
RSS Rants (19)
RSS Restaurants (8)
RSS Science (34)
RSS Spain (16)
RSS Travel (42)
RSS Video (20)
RSS Webcam (3)
RSS Writing (10)

Blogs I Read

 
Scrum Sucks
Ben Forta
Ray Camden
Kinky Solutions
Gary Gilbert
Red Hat Blogs
O'Reilly Digital Media
O'Reilly Radar
John Nack
The Strobist
Scott Kelby
Matt Kloskowski
Joe McNally
Digital Photography School
Engadget
Science Blog

RSS

 


Add to Google
Add to My Yahoo!

Aggregated By

 


Consumed By Feed-Squirrel.com
Aggregated by ColdFusionBlogger.org

Credits and Stuff

 
BlogCFC - Free ColdFusion Powered Blog Software
CJM Group - ColdFusion Website Hosting


 
 
blog | photos | flickr | referers | webcam | stats | about | contact
 
Copyright © 2009 Steven Erat. All rights reserved.
This is a personal weblog. The opinions expressed here represent my own and not those of my employer