From: Anthony Liguori <aliguori@us.ibm.com>
To: xen-devel <xen-devel@lists.xensource.com>
Subject: [PATCH 2/2] Make sure that TCP binds don't fail because of stale state
Date: Wed, 14 Sep 2005 20:38:27 -0500 [thread overview]
Message-ID: <4328D093.9080103@us.ibm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 711 bytes --]
SO_REUSEADDR does not immediately free up a port when a server is killed
with a signal (which is what we do for xend stop). Since there is no
great way (at least, that I know of) to deal with this, the following
patch implements a 30 second timeout for bind to help make it highly
unlikely that we'll get burned by this.
On a very slow system, killing xend with a signal takes less than a
second for the port to become available again so 30 seconds seems really
safe. With this patch (and the previous one), I can execute the following:
while true; do xend restart && xm list || break; done
And it runs without any trouble (I ran it for an hour before finally
giving up).
Regards,
Anthony Liguori
[-- Attachment #2: 6819_xend-race.diff --]
[-- Type: text/x-patch, Size: 1728 bytes --]
# HG changeset patch
# User anthony@localhost.localdomain
# Node ID 13d6ca9c35dd02770901b9a8f9f2e53c7ed500c5
# Parent 8c866d412673e4169386ee5c96ba10f20f54bf6c
SO_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@us.ibm.com>
diff -r 8c866d412673 -r 13d6ca9c35dd tools/python/xen/web/tcp.py
--- a/tools/python/xen/web/tcp.py Wed Sep 14 23:47:37 2005
+++ b/tools/python/xen/web/tcp.py Thu Sep 15 00:58:12 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):
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
reply other threads:[~2005-09-15 1:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4328D093.9080103@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.