4

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.

blahdiblah
  • 33,069
  • 21
  • 98
  • 152
user491880
  • 4,709
  • 4
  • 28
  • 49

2 Answers2

2

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.

user681107
  • 36
  • 1
  • 2
    If the call that was interrupted here is the socket read, doesn't this risk that you run the same insert query twice and end up with duplicate data? – André Caron Dec 17 '15 at 05:27
1

I was experiencing the same error. In my case it was caused by two different installations of the mysql-gem, one installed with rvm gem and the other from the default osx ruby. When I was running the default osx ruby but using bundler to get the rvm installed gem the binaries must have been from the wrong ruby.

Checking rvm environment and using only rvm installed gems and bundler fixed the problem.

hvrauhal
  • 432
  • 3
  • 13