ColdFusion Mail Spool Lock

Recently I've seen posts on both the CF-Talk list at House of Fusion and the Adobe ColdFusion Forum about a lock on the CF Mail Spool. At some point messages in the spool recycle over and over, without processing out to the mail server or going in to the undelivered folder.

I was working for a small regional internet service provider when I began working as a ColdFusion developer. We hosted around six hundred corporate sites, most of which used the <cfmail> tag in some form of form processing or another. This was back in the days of ColdFusion 4.0, and was when I first encountered this issue, and I've seen it several times since.

Basically what happens is the ColdFusion server loses it's connection to the mail server momentarily. Typically you'll see an error in your ColdFusion mail.log file that will state that the connection to your mail server failed at some point. When this happens there is a file lock on a .cfmail file in the spool that was being processed at the time the failure occurred. The connection comes back, but the file lock seems to cause a continual loop on the spool, which disallows the flow of files from the spool to the mail server. It often goes unnoticed until a client calls in to complain that they haven't recieved any leads from their site.

The issue is really easy to get around, but does require you to take down ColdFusion services for a moment so that the file lock is released. Here is a general outline of what you should do.

  1. Stop ColdFusion services
  2. Cut and paste all .cfmail files from the spool folder into a temporary folder.
  3. Restart ColdFusion services
  4. Verify the mail server connection in the ColdFusion Administrator
  5. Drag .cfmail files from the temp folder back into the spool folder at about 200 messages at a time, waiting for all messages to process out of the spool before moving to the next batch.

That's it. Pretty easy to handle. Your greatest hurdle is convincing a shared hosting provider that this needs to be done, but if they watch the spool folder and notice the same messages re-enter the spool repeatedly, without dropping to the undelivered folder, then it is a solid indicator that this is what has occured. All files leave the spool and show up five, ten, even fifteen minutes later. I have now worked for two separate hosting companies running everything from ColdFusion 4 through 7, and have seen it occur on each version at one time or another. Hope this helps someone!

TweetBacks
Comments
shobs's Gravatar This did not resolved my issue of mail connection failure. I do see .cfmail files in u
in undeliverable folder and not in spool folder.
# Posted By shobs | 1/31/07 2:27 PM
Cutter's Gravatar Shobs,

This method will reset a deadlock you might have on your active spool, but it won't resolve connection issues to your mail server. That's something else altogether, generally relating to errors in DNS, a change of IP address, or just outside networking connection issues in general.
# Posted By Cutter | 2/1/07 10:22 PM
shobs's Gravatar It was a virus scan configuration issue, which was blocking port 25 for outgoing mass mail.
# Posted By shobs | 2/2/07 12:32 PM
iyactlshadow's Gravatar This worked perfectly for my ColdFusion MX 7 server. Thanks for the solution!
# Posted By iyactlshadow | 5/18/07 3:04 PM
pat's Gravatar I came across this same problem earlier this week and it took a little while to figure out... all is clear now though.

One thing that I noticed that I'm not sure is different than one you came across is that all the .cfmail files that caused the lock were empty. They had a file size of 702 bytes or so, so weren't 0 byte files, but there was no text when you opened up the file. So I had to delete each of those files when I came across a lock.

I was thinking of writing a scheduled job that would check the spool directory each night and look for files older than a day old or so, and send an alert if there were. Except, ColdFusion wouldn't be able to actually send the mail in that case.

Can you think of any other ways that I could search for these old mail files? We had old mail from about 2-3 weeks in the spool folder, and didn't come across the problem until we started getting hard errors from CFMail 3 days ago.
# Posted By pat | 8/30/07 10:21 AM
Cutter's Gravatar That is odd. With a size of 702 bytes, I wonder what you would see looking at the source. The size sounds familiar, like a cfdump that isn't properly wrapped in a full html wrapper (html, head, and body tags).

As far as your scheduled task, you might be able to use the SMS gateway to send a text message in the event of a lock. Just an idea...
# Posted By Cutter | 8/30/07 11:55 AM
Mary's Gravatar This worked for us! Thanks heaps!
# Posted By Mary | 4/15/08 7:23 PM
mik muller's Gravatar Yikes. A client of mine just contacted me and said they haven't had any mail sent since 10/25. I just looked at their C:\CFusionMX7\Mail\Spool folder and there's over 16,000 files in there. Doing this 200 at a time will take a loooooooooong time!
# Posted By mik muller | 11/11/08 3:45 PM
Steve 'Cutter' Blades's Gravatar @Mik -

Yeah, I was being conservative on the side of caution. I think most of the time I could get away with doing them 1,000 at a time. For future use, Andy Matthews, a co-worker of mine also wrote a handy utility that can run as a scheduled task to reprocess your undelivered items, the Undelivrnator:

http://undelivrnator.riaforge.org/
# Posted By Steve 'Cutter' Blades | 11/11/08 9:59 PM
Steve's Gravatar Worked for me on CF 6.1, thanks for info!
# Posted By Steve | 5/14/09 9:57 AM
BarryC's Gravatar This worked for us running CF 5. We were working on this issue for about 4 hours and this fixed it in about 15 minutes. Thanks for the post.
# Posted By BarryC | 7/1/09 3:06 PM
Dino's Gravatar It worked perfect for me in CF8!!
thx for info
# Posted By Dino | 8/7/09 1:49 AM
tad's Gravatar Yep - worked for me on CF8 too. Thanks!
# Posted By tad | 10/22/09 8:26 AM
David's Gravatar This is a common problem for my ColdFusion 5.x box. ColdFusion's connection to our E-Mail server grinds to a halt when large E-Mail campaigns are generated (from another source, not ColdFusion), causing mail to stack up in the spool folder. When I realize mail has backlogged I log into the server, move the all the undeliverable .cfmail files to the spool folder again, and restart the ColdFusion Application Server service. Problem solved. Aside from having a dedicated E-Mail server for ColdFusion to use that doesn't get bogged down at any point, the only solution is to set up a .bat file in Windows Scheduler that can restart the ColdFusion service automatically at a given time, then creating a quick script to move undeliverable .cfmail files back into the spool.
# Posted By David | 12/17/09 7:17 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.3.006. Contact Blog Owner. Layout inspired by bluerobot.com., with some JQuery thrown in for fun.