Created
November 3, 2016 00:59
-
-
Save shortdudey123/eb901f7b541e629771b7a0809acfa12d to your computer and use it in GitHub Desktop.
Ruby Socket.gethostbyname random failures
This file contains hidden or 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
ruby:2.3.1-alpine | |
/ # ruby test.rb | |
Failed after 10729 successes | |
SocketError | |
getaddrinfo: Try again | |
test.rb:8:in `gethostbyname' | |
test.rb:8:in `<main>' | |
/ # | |
/ # ruby --version | |
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux] | |
/ # uname -a | |
Linux ruby-01 3.10.0-327.4.4.el7.x86_64 #1 SMP Tue Jan 5 16:07:00 UTC 2016 x86_64 Linux | |
/ # cat /etc/*release | |
3.4.4 | |
NAME="Alpine Linux" | |
ID=alpine | |
VERSION_ID=3.4.4 | |
PRETTY_NAME="Alpine Linux v3.4" | |
HOME_URL="http://alpinelinux.org" | |
BUG_REPORT_URL="http://bugs.alpinelinux.org" | |
/ # |
This file contains hidden or 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
ruby:2.3.1-slim | |
root@ruby-01:/# ruby test.rb | |
^CExited after 34594 successes | |
root@ruby-01:/# | |
root@ruby-01:/# ruby --version | |
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux] | |
root@ruby-01:/# uname -a | |
Linux ruby-01 3.10.0-327.4.4.el7.x86_64 #1 SMP Tue Jan 5 16:07:00 UTC 2016 x86_64 GNU/Linux | |
root@ruby-01:/# cat /etc/*release | |
PRETTY_NAME="Debian GNU/Linux 8 (jessie)" | |
NAME="Debian GNU/Linux" | |
VERSION_ID="8" | |
VERSION="8 (jessie)" | |
ID=debian | |
HOME_URL="http://www.debian.org/" | |
SUPPORT_URL="http://www.debian.org/support" | |
BUG_REPORT_URL="https://bugs.debian.org/" | |
root@ruby-01:/# |
This file contains hidden or 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/ruby | |
require 'resolv' | |
counter = 0 | |
begin | |
while true do | |
begin | |
Socket.gethostbyname('www.google.com') | |
counter += 1 | |
rescue | |
puts "Failed after #{counter} successes" | |
puts $!.class | |
puts $!.message | |
puts $!.backtrace | |
break | |
end | |
end | |
rescue SystemExit, Interrupt | |
puts "Exited after #{counter} successes" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The crashing and slowness are two different issues. Based on the results so far
Besides the ruby code, we can also use sh script