Skip to content

Instantly share code, notes, and snippets.

@shortdudey123
Created November 3, 2016 00:59
Show Gist options
  • Save shortdudey123/eb901f7b541e629771b7a0809acfa12d to your computer and use it in GitHub Desktop.
Save shortdudey123/eb901f7b541e629771b7a0809acfa12d to your computer and use it in GitHub Desktop.
Ruby Socket.gethostbyname random failures
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"
/ #
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:/#
#!/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
@xjlu
Copy link

xjlu commented Nov 3, 2016

The crashing and slowness are two different issues. Based on the results so far

  1. Alpine based images could cause getaddr crash in ruby, if we move away from alpine based image, we may be able to solve this issue.
  2. Other type of ruby images have the same issue of slowness as python, or just simple curl. These facts point to the possible culprit of kubernetes issue.

Besides the ruby code, we can also use sh script

for i in $(seq 1 100); \
do \
curl -o /dev/null -s -w "DNS-Lookup [%{time_namelookup}] Time-Connect [%{time_connect}] Time-PreTransfer [%{time_pretransfer}] Time-StartTransfer [%{time_starttransfer}] Total-Time [%{time_total}]\n" https://www.google.com/ ; \
done
``` to test the name lookup time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment