Skip to content

Commit

Permalink
Merge pull request #60 from hanazuki/fd-leak
Browse files Browse the repository at this point in the history
test_dns: Fix FD leak
  • Loading branch information
nobu authored Sep 10, 2024
2 parents c152f38 + 236c38b commit 366654e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/resolv/test_dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,10 @@ def test_multiple_servers_with_timeout_and_truncated_tcp_fallback
u1.send(msg[0...512], 0, client_address, client_port)
end

tcp_server1_thread = Thread.new { t1.accept; t1.close }
tcp_server1_thread = Thread.new do
# Keep this socket open so that the client experiences a timeout
t1.accept
end

tcp_server2_thread = Thread.new do
ct = t2.accept
Expand Down Expand Up @@ -800,7 +803,7 @@ def test_multiple_servers_with_timeout_and_truncated_tcp_fallback
ct.send(msg, 0)
ct.close
end
result, = assert_join_threads([client_thread, udp_server1_thread, tcp_server1_thread, tcp_server2_thread])
result, _, tcp_server1_socket, = assert_join_threads([client_thread, udp_server1_thread, tcp_server1_thread, tcp_server2_thread])
assert_instance_of(Array, result)
assert_equal(50, result.length)
result.each_with_index do |rr, i|
Expand All @@ -809,6 +812,8 @@ def test_multiple_servers_with_timeout_and_truncated_tcp_fallback
assert_equal("192.0.2.#{i}", rr.address.to_s)
assert_equal(3600, rr.ttl)
end
ensure
tcp_server1_socket&.close
end
end
end
Expand Down

0 comments on commit 366654e

Please sign in to comment.