WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] O_REUSEADDR is not enough to ensure we don't get address

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] O_REUSEADDR is not enough to ensure we don't get address in use errors when
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 15 Sep 2005 02:18:11 +0000
Delivery-date: Thu, 15 Sep 2005 02:16:43 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User shand@xxxxxxxxxxxxxxxxxxxxxxxxxxx
# Node ID 36f8c5900e8646b0465d92d602bd07f3d3b5a966
# Parent  7985a4d8bae9e8f618215d8da427320a8943b507
O_REUSEADDR is not enough to ensure we don't get address in use errors when
xend dies from a signal.

We implement a 30 second time to ensure we don't fail if we don't have to.

Signed-off-by: Anthony Liguori <aliguori@xxxxxxxxxx>

diff -r 7985a4d8bae9 -r 36f8c5900e86 tools/python/xen/web/tcp.py
--- a/tools/python/xen/web/tcp.py       Thu Sep 15 01:45:51 2005
+++ b/tools/python/xen/web/tcp.py       Thu Sep 15 01:46:40 2005
@@ -18,6 +18,7 @@
 import sys
 import socket
 import types
+import time
 
 from connection import *
 from protocol import *
@@ -35,8 +36,25 @@
     def createSocket(self):
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-        addr = (self.interface, self.port)
-        sock.bind(addr)
+
+        # SO_REUSEADDR does not always ensure that we do not get an address
+        # in use error when restarted quickly
+        # we implement a timeout to try and avoid failing unnecessarily
+
+        timeout = time.time() + 30
+        again = True
+        while again and time.time() < timeout:
+            again = False
+            try:
+                sock.bind((self.interface, self.port))
+            except socket.error, (errno, strerrno):
+                if errno == 98:
+                    again = True
+                else:
+                    raise socket.error(errno, strerrno)
+        if again:
+            raise socket.error(98, "address in use")
+                
         return sock
 
     def acceptConnection(self, sock, protocol, addr):

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] O_REUSEADDR is not enough to ensure we don't get address in use errors when, Xen patchbot -unstable <=