about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-04 04:17:31 +0000
committerEric Wong <normalperson@yhbt.net>2010-10-04 20:14:13 +0000
commit8612ccdd2f7f0c0b182ecc9616a76e97b879f6c0 (patch)
treeccb42511973a71f70e663cd3d14db8124f07313a /test
parent206d8c77bc0ac15a5c4e7a56aeff2e9fc280e6a3 (diff)
downloadunicorn-8612ccdd2f7f0c0b182ecc9616a76e97b879f6c0.tar.gz
While we've always unlinked dead sockets from nuked/leftover
processes, blindly unlinking them can cause unnecessary failures
when an active process is already listening on them.  We now
make a simple connect(2) check to ensure the socket is not in
use before unlinking it.

Thanks to Jordan Ritter for the detailed bug report leading to
this fix.

ref: http://mid.gmane.org/8D95A44B-A098-43BE-B532-7D74BD957F31@darkridge.com
(cherry picked from commit 1a2363b17b1d06be6b35d347ebcaed6a0c940200)
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_socket_helper.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/test/unit/test_socket_helper.rb b/test/unit/test_socket_helper.rb
index bbce359..c6d0d42 100644
--- a/test/unit/test_socket_helper.rb
+++ b/test/unit/test_socket_helper.rb
@@ -101,7 +101,14 @@ class TestSocketHelper < Test::Unit::TestCase
 
   def test_bind_listen_unix_rebind
     test_bind_listen_unix
-    new_listener = bind_listen(@unix_listener_path)
+    new_listener = nil
+    assert_raises(Errno::EADDRINUSE) do
+      new_listener = bind_listen(@unix_listener_path)
+    end
+    assert_nothing_raised do
+      File.unlink(@unix_listener_path)
+      new_listener = bind_listen(@unix_listener_path)
+    end
     assert UNIXServer === new_listener
     assert new_listener.fileno != @unix_listener.fileno
     assert_equal sock_name(new_listener), sock_name(@unix_listener)