script crashes with "Too many open files"

B

Bennett Haselton

I have a script that sends mail using the Mail::Bulkmail class from:
http://search.cpan.org/dist/Mail-Bulkmail/
I'm already using version 3.12 which according to that page is the
most recent available.

Even if you don't know the details of how Mail::Bulkmail works, I
suspect someone familiar with Perl or Linux internals may have a
suggestion on how to work around this problem.

After Mail::Bulkmail has been invoked, I think, a few hundred times,
the script crashes with the error message:
Could not initilize method (GOOD) to value (/var/www/good.txt) :
Could not open file /var/www/good.txt : Too many open files at ./send-
pending-messages-using-bulkmail.pl line 154.

Now the /var/www/good.txt file is specified in my bulkmail-config.txt
file as the file to write "good" addresses to. While the script is
running, the lsof command shows me these instances of handles on the
"good" file being already open:

peacefire:/var/www/html/circumventor# lsof -u root | grep good
send-pend 23961 root 6w REG 0,125 20427325
302910600 /var/www/good.txt
send-pend 23961 root 10w REG 0,125 20427325
302910600 /var/www/good.txt
send-pend 23961 root 13w REG 0,125 20427325
302910600 /var/www/good.txt
[...]

where the number of lines is the number of times that
Mail::Bulkmail::bulkmail() has been called. In other words, it looks
like each instance bulkmail() is opening a new file handle on good.txt
and not closing it properly.

After the script crashes, all the handles get closed automatically, so
I just have to restart the script and it's back up and running. But
can anyone guess a workaround that would allow the script to run
longer?

In the bulkmail config file I have these lines:
#log our errors
ERRFILE = /var/www/error.txt
BAD = /var/www/bad.txt
GOOD = /var/www/good.txt
banned = /var/www/banned.txt

So if I just commented the lines out completely, that might solve the
problem as nothing is logged any more, but I'd like to do some logging
so I'm hoping for a cleaner solution.

Bennett
 
U

Uri Guttman

BH> After Mail::Bulkmail has been invoked, I think, a few hundred times,
BH> the script crashes with the error message:

that line is a big clue. why do you invoke that module a few hundred
times? do you mean create new bulkmail objects or call some method a few
hundred times? without looking, i would expect a single bulkmail object
to be created and given the bulk addresses in a method.

BH> where the number of lines is the number of times that
BH> Mail::Bulkmail::bulkmail() has been called. In other words, it looks
BH> like each instance bulkmail() is opening a new file handle on good.txt
BH> and not closing it properly.

but why are you creating a new instance over and over? i suspect you are
not using the module properly.

uri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top