Bug #20403
closedTestResolvDNS#test_query_ipv4_address_truncated_tcp_fallback can flake if TCP port is in use
Description
The test TestResolvDNS#test_query_ipv4_address_truncated_tcp_fallback wants to make a TCP and UDP DNS server on the same port. It achieves this by binding to a random UDP port (with :0
), and then trying to bind to that TCP port. However, just because the UDP port was free, does not mean the TCP port was, so this can fail.
This leads to test failures like this one: https://github.com/ruby/ruby/actions/runs/8497267556/job/23275642160
1) Error:
TestResolvDNS#test_query_ipv4_address_truncated_tcp_fallback:
Errno::EACCES: Permission denied - bind(2) for "127.0.0.1" port 49701
D:/a/ruby/ruby/src/test/resolv/test_dns.rb:48:in 'TCPServer#initialize'
D:/a/ruby/ruby/src/test/resolv/test_dns.rb:48:in 'IO.new'
D:/a/ruby/ruby/src/test/resolv/test_dns.rb:48:in 'TestResolvDNS#with_tcp'
D:/a/ruby/ruby/src/test/resolv/test_dns.rb:181:in 'block in TestResolvDNS#test_query_ipv4_address_truncated_tcp_fallback'
D:/a/ruby/ruby/src/test/resolv/test_dns.rb:61:in 'TestResolvDNS#with_udp'
D:/a/ruby/ruby/src/test/resolv/test_dns.rb:179:in 'TestResolvDNS#test_query_ipv4_address_truncated_tcp_fallback'
Finished tests in 401.425882s, 64.4851 tests/s, 15534.2649 assertions/s.
25886 tests, 6235856 assertions, 0 failures, 1 errors, 502 skips
(note - it's EACCESS, not EADDRINUSE, because of this issue on Windows, I think: https://stackoverflow.com/questions/48478869/cannot-bind-to-some-ports-due-to-permission-denied)
Updated by kjtsanaktsidis (KJ Tsanaktsidis) 10 months ago
I opened https://github.com/ruby/ruby/pull/10413 for this.
Updated by Anonymous 10 months ago
- Status changed from Open to Closed
Applied in changeset git|80bda107c84187d90eeff9497d465e086364b420.
[ruby/resolv] Add an explicit with_udp_and_tcp helper to test_dns.rb
This helper tries to bind UDP and TCP sockets to the same port, by
retrying the bind if the randomly-assinged UDP port is already taken in
TCP. This fixes a flaky test.
[Bug #20403]