[Checkins] SVN: zc.ngi/trunk/ Bug fixed:

Jim Fulton jim at zope.com
Thu Jul 30 16:15:39 EDT 2009


Log message for revision 102400:
  Bug fixed:
  
  - zc.ngi.async bind failures weren't handled properly, causing lots of
    annoying log messages to get spewed, which tesnded to fill up log
    files.
  

Changed:
  U   zc.ngi/trunk/README.txt
  U   zc.ngi/trunk/src/zc/ngi/async.py
  U   zc.ngi/trunk/src/zc/ngi/tests.py

-=-
Modified: zc.ngi/trunk/README.txt
===================================================================
--- zc.ngi/trunk/README.txt	2009-07-30 19:59:01 UTC (rev 102399)
+++ zc.ngi/trunk/README.txt	2009-07-30 20:15:39 UTC (rev 102400)
@@ -17,6 +17,16 @@
 *******
 
 ==================
+1.1.3 (2009-07-30)
+==================
+
+Bugs fixed:
+
+- zc.ngi.async bind failures weren't handled properly, causing lots of
+  annoying log messages to get spewed, which tesnded to fill up log
+  files.
+
+==================
 1.1.2 (2009-07-02)
 ==================
 

Modified: zc.ngi/trunk/src/zc/ngi/async.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/async.py	2009-07-30 19:59:01 UTC (rev 102399)
+++ zc.ngi/trunk/src/zc/ngi/async.py	2009-07-30 20:15:39 UTC (rev 102400)
@@ -362,10 +362,14 @@
         else:
             family = socket.AF_INET
         self.create_socket(family, socket.SOCK_STREAM)
-        self.set_reuse_addr()
-        self.logger.info("listening on %r", self.addr)
-        self.bind(addr)
-        self.listen(255)
+        try:
+            self.set_reuse_addr()
+            self.logger.info("listening on %r", self.addr)
+            self.bind(addr)
+            self.listen(255)
+        except socket.error:
+            self.close()
+            raise
         notify_select()
 
     def handle_accept(self):
@@ -428,10 +432,14 @@
             family = socket.AF_UNIX
         else:
             family = socket.AF_INET
-        self.create_socket(family, socket.SOCK_DGRAM)
-        self.set_reuse_addr()
-        self.logger.info("listening on udp %r", self.addr)
-        self.bind(addr)
+        try:
+            self.create_socket(family, socket.SOCK_DGRAM)
+            self.set_reuse_addr()
+            self.logger.info("listening on udp %r", self.addr)
+            self.bind(addr)
+        except socket.error:
+            self.close()
+            raise
         notify_select()
 
     def handle_read(self):

Modified: zc.ngi/trunk/src/zc/ngi/tests.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/tests.py	2009-07-30 19:59:01 UTC (rev 102399)
+++ zc.ngi/trunk/src/zc/ngi/tests.py	2009-07-30 20:15:39 UTC (rev 102400)
@@ -67,6 +67,67 @@
 
     """
 
+def failure_to_bind_removes_listener_from_socket_map():
+    """
+    First, grab a port:
+
+    >>> import socket, random
+
+    >>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    >>> for i in range(1000):
+    ...    port = random.randint(10000, 30000)
+    ...    try: s.bind(('', port))
+    ...    except socket.error: pass
+    ...    else: break
+    ... else: print 'woops'
+
+    Get size of socket map:
+
+    >>> size = len(zc.ngi.async._map)
+
+    Now, trying to create a listener on the port should fail, and the
+    map should remain the same size.
+
+    >>> try: zc.ngi.async.listener(('', port), None)
+    ... except socket.error: pass
+    ... else: print 'oops'
+
+    >>> len(zc.ngi.async._map) == size
+    True
+
+    >>> s.close()
+
+    UDP:
+
+    >>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+    >>> for i in range(1000):
+    ...    port = random.randint(10000, 30000)
+    ...    try: s.bind(('', port))
+    ...    except socket.error: pass
+    ...    else: break
+    ... else: print 'woops'
+
+    Get size of socket map:
+
+    >>> size = len(zc.ngi.async._map)
+
+    Now, trying to create a listener on the port should fail, and the
+    map should remain the same size.
+
+    >>> try: zc.ngi.async.udp_listener(('', port), None)
+    ... except socket.error: pass
+    ... else: print 'oops'
+
+    >>> len(zc.ngi.async._map) == size
+    True
+
+    >>> s.close()
+
+
+
+
+    """
+
 class BrokenConnect:
 
     connected = failed_connect = __call__ = lambda: xxxxx



More information about the Checkins mailing list