about summary refs log tree commit homepage
path: root/t
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 04:17:50 +0000
commit1a2363b17b1d06be6b35d347ebcaed6a0c940200 (patch)
treedc0e5030525f630ded02405af307196f6b7c34c1 /t
parent505a9e72d320fe3ae521ceb0f381c1c0f5ae4389 (diff)
downloadunicorn-1a2363b17b1d06be6b35d347ebcaed6a0c940200.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
Diffstat (limited to 't')
-rw-r--r--t/t0011-active-unix-socket.sh79
1 files changed, 79 insertions, 0 deletions
diff --git a/t/t0011-active-unix-socket.sh b/t/t0011-active-unix-socket.sh
new file mode 100644
index 0000000..6f9ac53
--- /dev/null
+++ b/t/t0011-active-unix-socket.sh
@@ -0,0 +1,79 @@
+#!/bin/sh
+. ./test-lib.sh
+t_plan 11 "existing UNIX domain socket check"
+
+read_pid_unix () {
+        x=$(printf 'GET / HTTP/1.0\r\n\r\n' | \
+            socat - UNIX:$unix_socket | \
+            tail -1)
+        test -n "$x"
+        y="$(expr "$x" : '\([0-9]\+\)')"
+        test x"$x" = x"$y"
+        test -n "$y"
+        echo "$y"
+}
+
+t_begin "setup and start" && {
+        rtmpfiles unix_socket unix_config
+        rm -f $unix_socket
+        unicorn_setup
+        grep -v ^listen < $unicorn_config > $unix_config
+        echo "listen '$unix_socket'" >> $unix_config
+        unicorn -D -c $unix_config pid.ru
+        unicorn_wait_start
+        orig_master_pid=$unicorn_pid
+}
+
+t_begin "get pid of worker" && {
+        worker_pid=$(read_pid_unix)
+        t_info "worker_pid=$worker_pid"
+}
+
+t_begin "fails to start with existing pid file" && {
+        rm -f $ok
+        unicorn -D -c $unix_config pid.ru || echo ok > $ok
+        test x"$(cat $ok)" = xok
+}
+
+t_begin "worker pid unchanged" && {
+        test x"$(read_pid_unix)" = x$worker_pid
+        > $r_err
+}
+
+t_begin "fails to start with listening UNIX domain socket bound" && {
+        rm $ok $pid
+        unicorn -D -c $unix_config pid.ru || echo ok > $ok
+        test x"$(cat $ok)" = xok
+        > $r_err
+}
+
+t_begin "worker pid unchanged (again)" && {
+        test x"$(read_pid_unix)" = x$worker_pid
+}
+
+t_begin "nuking the existing Unicorn succeeds" && {
+        kill -9 $unicorn_pid $worker_pid
+        while kill -0 $unicorn_pid
+        do
+                sleep 1
+        done
+        check_stderr
+}
+
+t_begin "succeeds in starting with leftover UNIX domain socket bound" && {
+        test -S $unix_socket
+        unicorn -D -c $unix_config pid.ru
+        unicorn_wait_start
+}
+
+t_begin "worker pid changed" && {
+        test x"$(read_pid_unix)" != x$worker_pid
+}
+
+t_begin "killing succeeds" && {
+        kill $unicorn_pid
+}
+
+t_begin "no errors" && check_stderr
+
+t_done