direct-io.hg

changeset 13608:0843e4261753

[XEND] Ignore socket.shutdown() exceptions

Add further comments about why that shutdown() exists.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Thu Jan 25 14:52:36 2007 +0000 (2007-01-25)
parents 2a9b6b1f848f
children 21b9416d2215
files tools/python/xen/web/httpserver.py tools/python/xen/xend/server/XMLRPCServer.py
line diff
     1.1 --- a/tools/python/xen/web/httpserver.py	Thu Jan 25 13:05:15 2007 +0000
     1.2 +++ b/tools/python/xen/web/httpserver.py	Thu Jan 25 14:52:36 2007 +0000
     1.3 @@ -333,11 +333,15 @@ class HttpServer:
     1.4      def close(self):
     1.5          self.closed = True
     1.6          self.ready = False
     1.7 +        # shutdown socket explicitly to allow reuse
     1.8          try:
     1.9 -            # shutdown socket explicitly to allow reuse
    1.10 -            self.socket.shutdown(socket.SHUT_RDWR)
    1.11 +            self.socket.shutdown(2)
    1.12 +        except socket.error:
    1.13 +            pass
    1.14 +
    1.15 +        try:
    1.16              self.socket.close()
    1.17 -        except:
    1.18 +        except socket.error:
    1.19              pass
    1.20  
    1.21      def getServerAddr(self):
     2.1 --- a/tools/python/xen/xend/server/XMLRPCServer.py	Thu Jan 25 13:05:15 2007 +0000
     2.2 +++ b/tools/python/xen/xend/server/XMLRPCServer.py	Thu Jan 25 14:52:36 2007 +0000
     2.3 @@ -188,14 +188,22 @@ class XMLRPCServer:
     2.4  
     2.5      def cleanup(self):
     2.6          log.debug('XMLRPCServer.cleanup()')
     2.7 -        try:
     2.8 -            if hasattr(self, 'server'):
     2.9 -                # shutdown socket explicitly to allow reuse
    2.10 -                self.server.socket.shutdown(socket.SHUT_RDWR)
    2.11 +        if hasattr(self, 'server'):
    2.12 +            try:
    2.13 +                # This is here to make sure the socket is actually
    2.14 +                # cleaned up when close() is called. Otherwise
    2.15 +                # SO_REUSEADDR doesn't take effect. To replicate,
    2.16 +                # try 'xend reload' and look for EADDRINUSE.
    2.17 +                #
    2.18 +                # May be caued by us calling close() outside of
    2.19 +                # the listen()ing thread.
    2.20 +                self.server.socket.shutdown(2)
    2.21 +            except socket.error, e:
    2.22 +                pass # ignore any socket errors
    2.23 +            try:
    2.24                  self.server.socket.close()
    2.25 -        except Exception, exn:
    2.26 -            log.exception(exn)
    2.27 -            pass
    2.28 +            except socket.error, e:
    2.29 +                pass
    2.30  
    2.31      def shutdown(self):
    2.32          self.running = False