From 94d49ed31c39002335eeee65d42463139f561954 Mon Sep 17 00:00:00 2001 From: Masaki Matsushita Date: Thu, 26 Nov 2020 16:07:28 +0900 Subject: Add a hook before fork() for getaddrinfo_a() We need stop worker threads in getaddrinfo_a() before fork(). This change adds a hook before fork() that cancel all outstanding requests and wait for all ongoing requests. Then, it waits for all worker threads to be finished. Fixes [Bug #17220] --- test/socket/test_socket.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb index f1ec927c4c..04d677c747 100644 --- a/test/socket/test_socket.rb +++ b/test/socket/test_socket.rb @@ -102,6 +102,16 @@ class TestSocket < Test::Unit::TestCase assert_nothing_raised('[ruby-core:29427]'){ TCPServer.open('localhost', 0) {} } end + def test_getaddrinfo_after_fork + skip "fork not supported" unless Process.respond_to?(:fork) + assert_normal_exit(<<-"end;", '[ruby-core:100329] [Bug #17220]') + require "socket" + Socket.getaddrinfo("localhost", nil) + pid = fork { Socket.getaddrinfo("localhost", nil) } + assert_equal pid, Timeout.timeout(30) { Process.wait(pid) } + end; + end + def test_getnameinfo assert_raise(SocketError) { Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) } -- cgit v1.2.3