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?
Looking For A New Job?
- Web Applications Developer at Virginia Commonwealth University
- ColdFusion Web Application Developer at SiteVision, Inc.
- PROJECT MANAGER (REMOTE / ONSITE) at SiteVision, Inc.
- Ruby Developer at Cavulus
- 10+ Year ColdFusion Developer to Manage CF Existing Website at AtPrime Media Services
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.
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?
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?
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?
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...
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.
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).
@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."
We get the temp directory by calling this api on app server
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?
Good point - shared hosting or not.
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.
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 ().
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.
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
Does the empty string get returned everytime once it starts or just randomly on occasion?
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.
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?
Probably that could give us some clue.
I'm rockin' that scenario right now even for my site (I am on the same production server):
I have also output the GetTempDirectory() which is empty.
The output is empty.
Ben, interesting spam comments happening here - 'sohbet' repeating something you posted earlier, then JSC replying... both with links to spam domains.
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.
I am on a shared host and get this issue quite often. Support has been less than supportive and I don't blame them, i am not sure if there is an answer for this. Sometimes this issue crops up once ever few weeks, lately it has been every few days. Even after the server has been rebooted and the site comes back, I get NULL when try to see what the temp path is. Has anyone come up with any answers?
I had recently ran into this same issue.
I had followed one of your example on how to re-size images. http://www.bennadel.com/blog/1638-Ask-Ben-CFImage-And-Dynamic-Image-Compression-With-File-Size-Limits.htm
And ran into this getTempDirectory() returns empty string issue.
I wonder after all these years, if there is a stable solution to this issue?
if not, how can I removed the usage of GetTempDirectory() in resizing image?
20 months later... is this still the case? Is getTempDirectory() still buggy? I checked the Adobe Bugbase and didn't find any reports of this bug searching for ColdFusion 9 or 10. Has this been fixed or are all devs still avoiding using it?
I've started just using a "scratch" directory above my webroot:
This way, I never have to worry.
What specifically is the significance of a scratch directory? In short, I don't get it. Seems to me it could be called anything, as long as it is not in the web root.
Ha, our app has been in production for 4 years and just ran into this today! Out of the blue! Guess this issue is not resolved, at least on CF9.