Making TCPSocket.new "Happy"!
summary
Adds Happy Eyeballs v2 to TCPsocket.new implemented in C, reimplementing parallel name resolution per address family with detached threads, pipes and a single select loop; uses resolution delay 50ms and connection attempt 250ms timing and cancels other connects on success. Fixes: immediate retry when all prior connects fail (avoids spurious connection timeout), replaces raw select with RBThreadFDSelect to avoid FD_SET limits (prevents segfault), and lands in Ruby 3.4 with a slight benchmark overhead but up to 132× speedup in worst-case DNS stalls.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 1:20Happy Eyeballs v2 overview
- 6:51Improving Socket.tcp
- 13:40TCPSocket.new implementation
- 21:40Fixing connection timeout bug
- 24:01Handling large file descriptors
- 26:41Enabling Happy Eyeballs by default
- 27:41Performance impact and results
- 29:10Conclusion and thanks
related talks
29mThe Less-Told Story of Socket Timeouts
26mTCP Sockets Programming in Ruby
01h 01mWhat I learned from sockets
36mThe Little Server That Could
35mLet's build a simple HTTP server with Ruby
15mHA/TCP: A Reliable and Scalable Framework for TCP Network Functions
44mTCP memory isolation on multi-tenant servers
26mConcurrency in Ruby: From fork() to Fiber
