EINTR Error Causing Failure in E-mail Sending Script

Discussion in 'Ruby' started by Ben Gribaudo, Apr 14, 2005.

  1. Ben Gribaudo

    Ben Gribaudo Guest

    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
     
    Ben Gribaudo, Apr 14, 2005
    #1
    1. Advertising

  2. Ben Gribaudo

    Tanaka Akira Guest

    In article <>,
    Ben Gribaudo <> 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
     
    Tanaka Akira, Apr 15, 2005
    #2
    1. Advertising

  3. Ben Gribaudo

    Ben Gribaudo Guest

    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.
    >
    >
     
    Ben Gribaudo, Apr 15, 2005
    #3
  4. Ben Gribaudo

    Tanaka Akira Guest

    In article <>,
    Ben Gribaudo <> 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
     
    Tanaka Akira, Apr 17, 2005
    #4
  5. Hi,

    In message "Re: EINTR Error Causing Failure in E-mail Sending Script"
    on Sun, 17 Apr 2005 11:27:54 +0900, Tanaka Akira <> 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.
     
    Yukihiro Matsumoto, Apr 17, 2005
    #5
  6. Ben Gribaudo

    Tanaka Akira Guest

    In article <>,
    Yukihiro Matsumoto <> 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
     
    Tanaka Akira, Apr 18, 2005
    #6
  7. Ben Gribaudo

    Ben Gribaudo Guest

    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.
    >
    >
     
    Ben Gribaudo, Apr 19, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    55,604
  2. Replies:
    0
    Views:
    1,481
  3. Replies:
    2
    Views:
    4,480
  4. Don Quijote de Nicaragua

    Error + Send Mail + ERROR: Failure sending mail.

    Don Quijote de Nicaragua, Jun 26, 2008, in forum: ASP .Net
    Replies:
    5
    Views:
    1,535
    Don Quijote de Nicaragua
    Jun 26, 2008
  5. Bryan Richardson

    Socket#read raising Errno::EINTR

    Bryan Richardson, Apr 7, 2009, in forum: Ruby
    Replies:
    1
    Views:
    173
    Loga Ganesan
    Apr 7, 2009
Loading...

Share This Page