ColdFusion GetTempDirectory() Stops Working

Posted December 20, 2007 at 10:56 AM

Tags: ColdFusion

I just went and removed the usage of GetTempDirectory() in one of my applications because every now and then, ColdFusion's GetTempDirectory() starts returning an empty string. It's almost as if there is some error being thrown by the machine and, instead of letting that error bubble up to the web application, ColdFusion catches it and just returns an empty string.

Restarting the server fixes the issue, but certainly, that is not a viable option on our production machine that host as many sites as ours (I think some of our clients just look for reasons to call up and yell ;)).

Has anyone else ever come across this? Is there anything that can be done to prevent this other than just removing the use of ColdFusion's GetTempDirectory()? Does anyone feel that using GetTempDirectory() should be considered less than a best practice?

Post Comment  |  Ask Ben  |  Other Searches  |  Print Page




Reader Comments

Dec 20, 2007 at 11:34 AM // reply »
5 Comments

Funny... I thought I was crazy one day when I hit a similar problem. I didn't get an empty string, but it returned null and thus I was getting null pointer exceptions. Then I checked the docs and it turns out this is known behavior. I did indeed stop using the function.

Good luck Ben.


Dec 20, 2007 at 11:46 AM // reply »
7,572 Comments

@Marc,

I posted this problem back in May to the House of Fusion mailing list and didn't get any replies, so I just assumed that I was the only one :) Then, it just happened again this morning. I couldn't find anything in Google; I can't believe I didn't see the note in the live docs. Is it actually part of the docs? Or is it just in the comments?


Dec 20, 2007 at 11:56 AM // reply »
41 Comments

I don't understand why someone would use the gettempdirectory() over just creating an application variable and assigning it a directory path. What benefits do you get by using it?


Dec 20, 2007 at 11:59 AM // reply »
2 Comments

What version of ColdFusion and what platform are you guys running on? I don't believe I've ever seen this error occur, but maybe it would explain some "random" NPEs I've seen.

Also, I looked in the livedocs for 6.1 and 7 and didn't see any mention of this. Where is this issue documented?


Dec 20, 2007 at 12:03 PM // reply »
5 Comments

Weird, Ben. I'm certain I read this in the docs... I didn't make it up myself! But I can't find it anywhere. Down the memory hole I suppose...


Dec 20, 2007 at 12:05 PM // reply »
7,572 Comments

@Tony,

I think the only think you gain is not having to assign a variable in the Application :) I use it mostly for File Uploads when I need to upload a file, then rename it, then move it. The temp directory just seems like the kind of place that stuff should be done.

@Leon,

We are using ColdFusion 7.0.2 I think. Definitely some brand of MX7, which updater I am not exactly sure. However, it has happened on both the production and the Dev machines, but at different times. Both machines are running Windows Sever 2003 (I think, but I am not really involved in the server setup).


Dec 20, 2007 at 1:26 PM // reply »
188 Comments

@Ben, because our clients are on a shared box, we've always manually setup a temp directory for them as one global location is a "bad idea."


Dec 20, 2007 at 1:54 PM // reply »
25 Comments

Ben,
We get the temp directory by calling this api on app server

ServletContext.getAttribute("javax.servlet.context.tempdir")

And we get this only the first time after which it is cached. So the only case you can get empty space is when the app server returns this value as empty String which looks little unlikely. Bid you change the temporary directory value in jrun.xml by any chance?
Is there any way I can replicate this?


Dec 20, 2007 at 2:22 PM // reply »
7,572 Comments

@Todd,

Good point - shared hosting or not.

@Rupesh,

I don't know how to reproduce it. It seems to only happen occasionally. From what you are saying, though, it seems like if it hiccups occasionally on startup, then it is in trouble till the next reboot.

I don't know anything about the jrun.xml file, but I do not believe we have messed with it.


JP
Dec 20, 2007 at 11:34 PM // reply »
2 Comments

I'm having the same problem... debugging FCKEditor 2.5, which uses GetTempDirectory () to upload files. My local server is returning an empty string (right now!), and FCKEditor doesn't check for it. I like the suggestion of setting a temp directory that your application uses. I'm going to modify FCKEditor so that I can set a temp directory in the configuration that defaults to GetTempDirectory ().


Dec 21, 2007 at 2:57 AM // reply »
5 Comments

I am also a fan of creating site-wide request variables for things like that!

Ben - I know you like recursion so if you really want to use the temp directory function, why not create your own UDF which basically keeps recursively calling the GetTempDirectory() method until it is not = '' or not = null

Not the most kosher approach, but it allows you to use the GetTempDirectory() directory.

:P


Dec 21, 2007 at 4:25 AM // reply »
18 Comments

Paolo, if GetTempDirectory() stops working until the server is restarted, calling the function recursively I would expect to crash the server, or at least timeout


Dec 21, 2007 at 4:33 AM // reply »
5 Comments

Does the empty string get returned everytime once it starts or just randomly on occasion?


Dec 21, 2007 at 7:18 AM // reply »
7,572 Comments

@Paolo,

Duncan is right - it's not randomly returning the empty string. It randomly starts returning the empty string, but once it does this, it keeps returning it until the server is restarted.


Dec 21, 2007 at 7:55 AM // reply »
25 Comments

In case you get into such state again where GetTempDirectry() is returning an empty String, can you let me know what is the output for this?

<cfoutput>#GetpageContext().getServletContext().getAttribute("javax.servlet.context.tempdir")#</cfoutput>

Probably that could give us some clue.


Dec 21, 2007 at 7:59 AM // reply »
7,572 Comments

@Rupesh,

I'm rockin' that scenario right now even for my site (I am on the same production server):

http://www.bennadel.com/test.cfm

I have also output the GetTempDirectory() which is empty.


JP
Dec 21, 2007 at 11:26 AM // reply »
2 Comments

<cfoutput>#GetpageContext().getServletContext().getAttribute("javax.servlet.context.tempdir")#</cfoutput>

The output is empty.


Apr 18, 2008 at 3:57 AM // reply »
18 Comments

Ben, interesting spam comments happening here - 'sohbet' repeating something you posted earlier, then JSC replying... both with links to spam domains.


Apr 18, 2008 at 7:14 AM // reply »
7,572 Comments

Yeah, this "sohbet" is a pain in the butt. I see he has been spamming other blogs (I get the blog comment subscriptions to). I think it is human though - it doesn't post with any kind of speed. Just got to the office now need to go clean out the spam.


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 20, 2010 at 12:07 PM
Drawing On The iPhone Canvas With jQuery And ColdFusion
Simply awesome. Saved my day. ... read »
Mar 20, 2010 at 9:00 AM
Building A Fixed-Position Bottom Menu Bar (ala FaceBook)
I would like to say thx for an easy way to create a bottom bar. I do have a ?. Is it possible to center the bar if i want to resize it to ex 85%. Regards Offenbach ... read »
Mar 19, 2010 at 7:26 PM
MySQL 3/4 - com.mysql.jdbc.Driver And allowMultiQueries=true
Thank you very much for this post. Adding allowMultiQueries="true" in context.xml didn't help until I added it to url as allowMultiQueries=true Good idea is to use prepared statements and it will he ... read »
Jim
Mar 19, 2010 at 4:49 PM
Nobody Puts Baby In The Corner!
Wow. This is like suddenly finding a support group for your secret shame. I'm not alone! I always liked this movie, even though it is extremely cheesy. I just wish Jennifer Grey hadn't gotten the ... read »
Mar 19, 2010 at 4:47 PM
Application.cfc OnRequest() Method Affects OnError() Arguments
@Jason and @Ben, I've been doing some CF9 refactoring on our systems and noticed an odd occurrence with onError as well. Found a way to work around my problem, but what I saw was... Background: Our ... read »
Jim
Mar 19, 2010 at 4:44 PM
Shoot 'Em Up Starring Clive Owen And Paul Giamatti
I actually enjoyed this movie quite a lot. It was different, certainly, but I think they were going for more of a Quentin Tarentino-"wow, that was weird"-vibe than an actual spoof. Once I realize ... read »
Mar 19, 2010 at 4:34 PM
An Intensive Exploration Of jQuery With Ben Nadel (Video Presentation)
Hey I guess the video is down. Is there anyway you can upload to youtube or vimeo or some other service? Greatly appreciated. ... read »
Mar 19, 2010 at 4:24 PM
ColdFusion CFPOP - My First Look
@Ben Thanks for the follow up! The root of the problem had to do with being able to trace bounced emails to specific records in a DB table. Let's say you run an email campaign and you get 1,000 bou ... read »