Search code examples
mysqlrubymechanize-ruby

`sysread': Interrupted system call (Errno::EINTR) When using Ruby and mysql


I'm scraping a site with mechanize and pushing to a mysql db. I am getting these sys read errors a lot and I'm not sure what the solution is. I'm using the Ruby-mysql gem.


Solution

  • I was doing the exact same thing (mechanize + mysql), and I solved it by wrapping my mysql calls with a begin/rescue/end clause:

    begin
      mysql_insert data
    rescue Interrupt, Errno::EINTR
      mysql_close connection
      connection = mysql_connect
      retry
    end
    

    Note that this puts your code in an infinite loop, if you use this in something real I would recommend putting some limiter on it. All the mysql_* are my own methods.