about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-06-30 17:47:55 -0700
committerEric Wong <normalperson@yhbt.net>2009-06-30 17:47:55 -0700
commitd247b5d95a3ad2de65cc909db21fdfbc6194b4c9 (patch)
tree56b5d7bebe156442e3e6ab983dae784d3142a2a3 /lib
parent8c2040127770e40e344a927ddc187bf801073e33 (diff)
downloadunicorn-d247b5d95a3ad2de65cc909db21fdfbc6194b4c9.tar.gz
This number of retries and delay taken directly from nginx
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 3c8c4c4..a2893fd 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -176,16 +176,23 @@ module Unicorn
     def listen(address, opt = {}.merge(@listener_opts[address] || {}))
       return if String === address && listener_names.include?(address)
 
-      if io = bind_listen(address, opt)
+      delay, tries = 0.5, 5
+      begin
+        io = bind_listen(address, opt)
         unless TCPServer === io || UNIXServer === io
           IO_PURGATORY << io
           io = server_cast(io)
         end
         logger.info "listening on addr=#{sock_name(io)} fd=#{io.fileno}"
         LISTENERS << io
-      else
+        return io
+      rescue Errno::EADDRINUSE => err
         logger.error "adding listener failed addr=#{address} (in use)"
-        raise Errno::EADDRINUSE, address
+        raise err if tries == 0
+        tries -= 1
+        logger.error "retrying in #{delay} seconds (#{tries} tries left)"
+        sleep(delay)
+        retry
       end
     end