Announcing:

LessConf 2012 will be Feb 23-24 in Atlanta, Georgia!
Register today and make us smile super big!

Path Variable Being "Unset"

written by Steven on January 16, 2009

We had an interesting bug recently that affected the Less Accounting website. One of the functions in Less Accounting is the ability to send invoices and proposals. The system let's you send them as an email or as a PDF file attached to an email, or you can download a PDF of the invoice. Recently we started seeing some problems with the PDF generator process. After a seemingly random period of time a mongrel would stop generating PDFs. Wait a little longer and another mongrel would fail until they were all failing. This also started happening more frequently; two weeks ago this was a rare occurrence, but a few days ago it would start failing almost immediately. Restarting the mongrels always fixed the problem, but obviously setting them to restart every five minutes was not acceptable.

Besides nil exceptions, the only other exception raised was a Broken Pipe Exception. Since no output was being generated by the PDF service for these failed PDFs I started adding all kinds of debug info. Due to the Broken Pipe Exception I started to suspect a problem with file descriptors. I even rewrote the generation code to use files as input and output instead of stdin and stdout. Once I had the raw input as files I could run the PDF generation manually which always worked. The oddest part was that this happened over time, the same input would succeed after a restart, but not a short time later.

Lourens Naudé took some time with me to help sort this out. We used strace on the mongrels and when that didn't help I added strace to the PDF generator. What was odd was that strace didn't log anything when there was a failure, just as the PDF generator didn't log anything on failure. I decided to log the command that calls the PDF generator and discovered that the failures were caused by the PDF generator not being called at all.

The lib shelled out `which` to get the path to the generator and at some point `which` could no longer find the command. It acted as if the $PATH variable was being unset. The generator is in the same location in dev and production, so hard coding the path fixed the problem.

I'm not sure why the path variable would be unset and didn't have time to investigate further. If you have any insights, please share them.

I hope you'll join us for LessConf 2012, Feb 23-24, 2012 in Atlanta Ga.
We're releasing our first ebook titled "How we built our consultancy to over $1,000,000 a year in revenue." Get early access to the ebook.

4 Comments

Lourens Naude
Lourens Naude said on January 16, 2009

Steve,

Could also cache the path on the first run ( memoize ) … piggy backing on your Mongrels not starting sleep walking either, off course.

Mark Turner
Mark Turner said on January 17, 2009

Does it happen to newly spawned Mongrels or do you restart them and eventually $path gets unset?

Mark Turner
Mark Turner said on January 17, 2009

Have you tried dumping out ‘env’ right before you call the PDF generation code?

Something like: logger.info “Environment: #{`env`}”

Steven Bristol
Steven Bristol said on January 18, 2009

@Mark,

I could have continued to debug, but honestly I can’t afford to spend anymore time on this.

Leave a Comment

About Steven
Steven Bristol has written code for the past 20 years. He like green vegetables and kittens, oh and butterflies too. He loves to throw ninja stars at his enemies.

You Should...

Follow Steven on Twitter
Friend Steven on Facebook
Subscribe
LessEverything Copyright 2011 LessEverything.com
We don't like footers, they're kinda boring