Problems using SocketServer.ThreadingTCPServer

Joao Prado Maia JMaia at lexgen.com
Wed Jan 30 20:08:02 CET 2002


Hi,

I sent an email to the list a couple of weeks ago about my python based
Usenet server, that was having some heavy CPU load on certain scenarios.
After debugging the code a little more, it turned out the bug was really
related to Outlook Express acting as a newsreader.

Outlook Express was sending (I can still reproduce this) 'empty' lines thru
the socket, so my little loop to get line by line of information sent by the
newsreader was going crazy with a spurious stream of 'empty' lines. From the
source code itself:

    def handle(self):
        settings.logEvent('Connection from %s' % (self.client_address[0]))
        self.send_response(STATUS_READYNOPOST % (settings.hostname,
__VERSION__))
        while not self.terminated:
            self.inputline = self.rfile.readline()
            if __DEBUG__:
                print self.inputline.strip()
            line = self.inputline.strip()
            # somehow outlook express sends a lot of newlines (maybe its
just my imagination)
            if (not self.sending_article) and (line == ''):
                self.broken_oe_checker += 1
                if self.broken_oe_checker >= 10:
                    self.send_response(STATUS_CLOSING)
                    self.terminated = 1
                continue
            self.tokens = line.split(' ')
            # NNTP commands are case-insensitive
            command = self.tokens[0].upper()
            settings.logEvent('Received request: %s' % (line))
            if command == 'POST':
                self.sending_article = 1
                self.send_response(STATUS_SENDARTICLE)
            else:
                if self.sending_article:
                    if self.inputline == '.\r\n':
                        self.sending_article = 0
                        self.do_POST()
                        self.article_lines = []
                        continue
                    self.article_lines.append(line)
                else:
                    if command in self.commands:
                        getattr(self, "do_%s" % (command))()
                    else:
                        self.send_response(ERR_NOTCAPABLE)
        settings.logEvent('Connection closed (IP Address: %s)' %
(self.client_address[0]))

Sorry if it is too much code by the way, but I didn't want to send just a
part of the function and someone ask for the full thing. Anyway, the check
that I do to see if it is an empty line works, but Outlook Express complains
that the connection died for 'apparently' no real reason. [ Note: if you
want to see the full source of this script, see
http://cvs.phpbrasil.com/chora/co.php/papercut/papercut.py?r=1.23 ]

Just so nobody thinks I'm crazy, the same problem is being experienced by
another python based project - Schicks. It is a SMTP server that uses the
same module (SocketServer.ThreadingTCPServer) as the base for the server.
The 'spurious' stream of empty lines is not an Outlook Express bug, since
there are several other NNTP server projects around that never experienced
this problem.

So it all boils down to the following - is my code (and Shicks' code as
well) completely broken or is something going on that I'm missing to check ?
I would love to hear something about people who have played with this a
little more, as I already lost countless hours trying to figure out what the
deal is.

Cheers,
Joao

--
Joao Prado Maia
Software QA
Bioinformatics Dept.
Lexicon Genetics, Inc.


*************************************************************************** 
 The contents of this communication are intended only for the addressee and
may contain confidential and/or privileged material. If you are not the
intended recipient, please do not read, copy, use or disclose this
communication and notify the sender.  Opinions, conclusions and other
information in this communication that do not relate to the official
business of my company shall be understood as neither given nor endorsed by
it.  
*************************************************************************** 






More information about the Python-list mailing list