[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

EINTR Error Causing Failure in E-mail Sending Script

Ben Gribaudo

4/14/2005 2:31:00 PM

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/lib...) 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



6 Answers

Tanaka Akira

4/15/2005 10:04:00 AM

0

In article <425E7EA3.9080801@bengribaudo.com>,
Ben Gribaudo <rubytalk@bengribaudo.com> writes:

> 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.
--
Tanaka Akira


Ben Gribaudo

4/15/2005 11:57:00 AM

0

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

Have a great day,
Ben


Tanaka Akira wrote:

>> 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

...

>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.
>
>



Tanaka Akira

4/17/2005 2:28:00 AM

0

In article <425FAC0D.8080409@bengribaudo.com>,
Ben Gribaudo <rubytalk@bengribaudo.com> writes:

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

replace sysread by readpartial in net/protocol.rb.
--
Tanaka Akira


Yukihiro Matsumoto

4/17/2005 3:33:00 PM

0

Hi,

In message "Re: EINTR Error Causing Failure in E-mail Sending Script"
on Sun, 17 Apr 2005 11:27:54 +0900, Tanaka Akira <akr@m17n.org> writes:

|> 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.


Tanaka Akira

4/17/2005 11:11:00 PM

0

In article <1113751962.230605.6545.nullmailer@x31.priv.netlab.jp>,
Yukihiro Matsumoto <matz@ruby-lang.org> writes:

> 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.
--
Tanaka Akira


Ben Gribaudo

4/19/2005 1:35:00 PM

0

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

Tanaka Akira wrote:

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