Happy Eyeballs (also called Fast Fallback) is an algorithm published by the IETF which can make dual-stack applications (those that understand both IPv4 and IPv6) more responsive to users by attempting to connect using both IPv4 and IPv6 at the same time (preferring IPv6), thus avoiding the usual problems faced by users with imperfect IPv6 connections or setups.
This was done to promote more webservers around the world to start supporting ipv6 and not penalize them for slower ipv6. That way, eventually, world would be a better place. As a default, when it all started, timeout for falling back to IPv4 was set as 300ms.
This post is to share the code that I wrote to quickly test who wins the race as per happy eyeballs. Sample output:-
➜ $?=0 @arastogi-mn3 golang/happy [ 8:06PM] (master|…)➤ go run main.go -server 'www.google.com:443' 2017/11/08 20:06:12 Connecting to server: www.google.com:443 with timeout: 300ms 2017/11/08 20:06:12 Connected to address: 126.96.36.199:443 in 68ms 2017/11/08 20:06:12 Connected to address: [2404:6800:4007:802::2004]:443 in 69ms 2017/11/08 20:06:12 As per happy eyeballs, IPv6 won! >>> 0s elasped... ➜ $?=0 @arastogi-mn3 golang/happy [ 8:06PM] (master|…)➤
Here, you can see that ipv6 is connected instead of ipv4 even though ipv4 is faster at that moment.