Skip to content

Instantly share code, notes, and snippets.

@dylanahsmith
Last active January 15, 2019 12:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanahsmith/10069061 to your computer and use it in GitHub Desktop.
Save dylanahsmith/10069061 to your computer and use it in GitHub Desktop.
mysql2 EINTR on connect prolonged timeout reproduction
#!/usr/bin/env ruby
require 'mysql2'
require 'rbconfig'
CONNECT_TIMEOUT = ARGV.empty? ? nil : ARGV.shift.to_i
trap("USR2") {}
HOST = case RbConfig::CONFIG["host_os"]
when /\Adarwin/
'127.0.0.2'
when /\Alinux/
'169.254.1.2'
else
ARGV.shift or abort("Usage: #{$0} HOST")
end
pid = fork do
client = Mysql2::Client.new(:host => HOST, :connect_timeout => CONNECT_TIMEOUT)
client.close
end
loop do
sleep 0.1
Process.kill("USR2", pid)
break if Process.waitpid(pid, Process::WNOHANG)
end
puts $?.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment