On Wed, 14 Mar 2007, Nobuyoshi Nakada wrote:

> At Wed, 14 Mar 2007 03:40:42 +0900,
> Hugh Sasse wrote in [ruby-core:10574]:
> > I've just received this message from cron.
> 
> > Your "cron" job on brains
> > /usr/local/bin/erb /home/hgs/public_html/ruby/ruby_sites.eruby >
> > /home/hgs/public_html/ruby/ruby_sites.html
> 
> Can't you show reproducable code, or backtrace?

Yes, but it's from an erb job run by cron, and that's all I got from cron
It was working fine till I upgraded

12 7,18 * * * /usr/local/bin/erb /home/hgs/public_html/ruby/ruby_sites.eruby > /home/hgs/public_html/ruby/ruby_sites.html

:r /home/hgs/public_html/ruby/ruby_sites.eruby

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>List of Active Ruby Sites</title>
    </head>
    <body>
        <h1>List of active Ruby Sites</h1>
        <%
        require 'net/http'
        require 'uri'
        require 'date'
        require 'timeout'

        # Get a list of sites to process
        class Site 
           attr_accessor :url, :name, :date, :failed
           def initialize(url, name)
              @url = url; @name = name;
              @date = DateTime.now;
              @failed = false
           end
        end
        Sites = [Site.new('http://www.ruby-lang.org/', 'www.ruby-lang.org/'),
                Site.new('http://redhanded.hobix.com/', 'Redhanded'),
                Site.new('http://www.ruby-doc.org/', 'Ruby-doc'),
                Site.new('http://www.rubyquiz.com/', 'Ruby Quiz'),
                Site.new('http://rubyforge.org/', 'RubyForge'),
                Site.new('http://rubyxml.com/', 'Ruby XML'),
                Site.new('http://raa.ruby-lang.org/', 'Ruby
                Application Archive'),
                Site.new('http://www.rubygarden.org/', 'RubyGarden')]
        Sites.each {|site|
            uri = URI.parse(site.url)
            host = uri.host
            port = uri.port
            path = uri.path
            begin
                Timeout::timeout(300) {
                    Net::HTTP.start(host, port) {|http|
                        response = http.request_head(path)
                        if response.key?('last-modified')
                            site.date = DateTime.parse(response['last-modified'])
                        else
                           site.date = DateTime.civil(1970)
                        end
                    }
                }
            rescue Timeout::Error
                site.failed = true
            end
        }
        %>
        <p>Note, Dates of 1970 mean the server doesn't provide a
        Last-Modified: header.</p>
        <ul><% Sites.sort_by{|x| x.date}.reverse.each{|site|
            unless site.failed
            %>
            <li><a href="<%= site.url %>"><%= site.name %> ...
                [<%= site.date.to_s %>]</a></li>
            <% else %>
            <li> Could not access <a href="<%= site.url %>"><%=
            site.name %> </li>
            <% end %>
            <% } %></ul>
        <p>Page generated <%= DateTime.now %> with erb </p>
    </body>
</html>

Running that command line by hand gives ... no errors now. 
Nothing like a live demonstration of a problem to make it disappear.

OK can I make timeout fail anyway
brains hgs 31 %> vim timeout_error.rb
brains hgs 32 %> ./timeout_error.rb
execution expired
brains hgs 33 %> ./timeout_error.rb
execution expired
brains hgs 34 %> ./timeout_error.rb
execution expired
brains hgs 35 %> cat !$
cat ./timeout_error.rb
#!/usr/local/bin/ruby -w

require 'timeout'

begin
   Timeout::timeout(3) {
     sleep 5
   }
rescue Timeout::Error => e
   puts e
end
brains hgs 36 %>

Apparently not. :-(

Any suggestions as to how I can make the failure more verbose next time
so I can give you something you can use?  If it fails again....

> 
> -- 
> Nobu Nakada
> 
> 
        Thank you, and apologies for the uselessness of this report.

        Hugh