[Spambayes-checkins] spambayes/scripts sb_server.py,1.41,1.42

Tony Meyer anadelonbrin at users.sourceforge.net
Wed Mar 9 02:58:12 CET 2005


Update of /cvsroot/spambayes/spambayes/scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8552/scripts

Modified Files:
	sb_server.py 
Log Message:
If a non-blocking socket is connect()ed, then it will return an error (could not complete
 without blocking), which doesn't tell us whether the connect() succeeded or failed.
  asyncore assumes that it succeeded and keeps going.  If it failed, then select.select()
 will report it as an error if the socket is checked (which is the case in Python
 2.4, but not earlier).  This results in a warning printed to stderr, and because
 the error never goes away, this error is printed for every iteration of the asyncore.loop()
 loop, which is *very* often.  This is the cause of the reasonably frequently reported
 "eating up all CPU" or "log file grows huge" bugs with 1.0.3.

If we set the socket to blocking for the connect call, then it will fail properly
 if it is going to, which we know how to handle.  We can then set it to nonblocking
 again after a successful connect.  This should fix the problems.

Backport candidate if there is a 1.0.4 (although this will only be a problem with
 Python 2.4).

Index: sb_server.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_server.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** sb_server.py	7 Feb 2005 22:57:38 -0000	1.41
--- sb_server.py	9 Mar 2005 01:58:09 -0000	1.42
***************
*** 150,158 ****
          self.set_terminator('\r\n')
          self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
!         # create_socket creates a non-blocking socket.  This is fine for
!         # regular sockets, but not for ssl - if it is non-blocking then the
!         # second ssl connection will fail.
!         if ssl:
!             self.socket.setblocking(1)
          try:
              self.connect((serverName, serverPort))
--- 150,161 ----
          self.set_terminator('\r\n')
          self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
!         # create_socket creates a non-blocking socket.  This is not great,
!         # because then socket.connect() will return errno 10035, because
!         # connect takes time.  We then don't know if the connect call
!         # succeeded or not.  With Python 2.4, this means that we will move
!         # into asyncore.loop(), and if the connect does fail, have a
!         # loop something like 'while True: log(error)', which fills up
!         # stdout very fast.  Non-blocking is also a problem for ssl sockets.
!         self.socket.setblocking(1)
          try:
              self.connect((serverName, serverPort))
***************
*** 193,198 ****
                      self.send = self.send_ssl
                      self.recv = self.recv_ssl
!                 self.socket.setblocking(0)
!                 print self._fileno
              
      def send_ssl(self, data):
--- 196,200 ----
                      self.send = self.send_ssl
                      self.recv = self.recv_ssl
!             self.socket.setblocking(0)
              
      def send_ssl(self, data):



More information about the Spambayes-checkins mailing list