Last active
January 15, 2019 12:46
-
-
Save dylanahsmith/10069061 to your computer and use it in GitHub Desktop.
mysql2 EINTR on connect prolonged timeout reproduction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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