EINTR Error Causing Failure in E-mail Sending Script

B

Ben Gribaudo

Hello,

The corporation I work for runs a paid mailing list powered by a Ruby
1.8.2 script running on a dual-processor Intel Pentium II Debian Woody
R4 server (kernal 2.4.19*)*.

Occasionally, we encounter a "Errno::EINTR Interrupted system call"
exception coming from /usr/lib/ruby/1.8/net/protocol.rb:197:in
`sysread'. This is the method of our application's code that calls the
Ruby library method which sometimes results in the error.
def mail(message)
Net::SMTP.start("localhost", 25) do |smtp|
smtp.sendmail(message.to_s, message.from.address,
message.to.address)
end
end

Some digging in the ruby-talk archives and on Google (found
http://www.delorie.com/gnu/docs/glibc/libc_498.html) make me think that
this error may be related to a threading/multi-tasking issue. (Note that
our mailer app does not create multiple threads but is run on a
multi-processor server.)

The impression I received from the ruby-talk archives on how to resolve
this issue is to catch the Errno::EINTR exception and retry the block
until the the code succeeds. Like:
def mail(message)
begin
Net::SMTP.start("localhost", 25) do |smtp|
smtp.sendmail(message.to_s, message.from.address,
message.to.address)
end
rescue Errno::EINTR
retry
end
end

Does this sound like a wise* and re*asonable solution? Can any of you
shed more light as to why we encounter the EINTR error? Is it a
threading/signal handling issue in Ruby or something we are doing in our
application or ... ?

Thank you,
Ben Gribaudo
 
T

Tanaka Akira

Ben Gribaudo said:
The impression I received from the ruby-talk archives on how to resolve
this issue is to catch the Errno::EINTR exception and retry the block
until the the code succeeds. Like:
def mail(message)
begin
Net::SMTP.start("localhost", 25) do |smtp|
smtp.sendmail(message.to_s, message.from.address,
message.to.address)
end
rescue Errno::EINTR
retry
end
end

Does this sound like a wise* and re*asonable solution? Can any of you
shed more light as to why we encounter the EINTR error? Is it a
threading/signal handling issue in Ruby or something we are doing in our
application or ... ?

I'm not sure why EINTR.

However I think it's better to restart sysread itself instead of
Net::SMTP.start.

readpartial can be used instead since 1.8.3. readpartial doesn't
raise EINTR.
 
B

Ben Gribaudo

Thank you for your thoughts, Tanaka. How would you suggest that I
restart sysread?

Have a great day,
Ben
 
T

Tanaka Akira

Ben Gribaudo said:
Thank you for your thoughts, Tanaka. How would you suggest that I
restart sysread?

replace sysread by readpartial in net/protocol.rb.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: EINTR Error Causing Failure in E-mail Sending Script"

|> Thank you for your thoughts, Tanaka. How would you suggest that I
|> restart sysread?
|
|replace sysread by readpartial in net/protocol.rb.

Did we discuss whether sysread should handle EINTR internally or not?
I'm afraid I forgot some reason not to handle it.

matz.
 
T

Tanaka Akira

Yukihiro Matsumoto said:
Did we discuss whether sysread should handle EINTR internally or not?
I'm afraid I forgot some reason not to handle it.

Since there is only signal, SIGVTALRM, which have a handler
without SA_RESTART in Ruby, there is no reason to handle EINTR in
script level, now.

However automatic restarting is a headache for proper signal handling,
as you considered to drop SA_RESTART in [ruby-dev:25762]. It is
applicable not only in C level but also in Ruby script level.
 
B

Ben Gribaudo

I thought readpartial was only available in Ruby 1.8.3. We're on 1.8.2.
Do you have any ideas for a 1.8.2 solution? Is the rescue/retry approach
I took OK?

Thank you,
Ben
 

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

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top