[Patches] [ python-Patches-946207 ] Non-blocking Socket Server

SourceForge.net noreply at sourceforge.net
Thu Feb 24 20:59:04 CET 2005


Patches item #946207, was opened at 2004-05-02 04:45
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=946207&group_id=5470

Category: Modules
Group: Python 2.3
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Jesper ´JJ´ Jurcenoks (jesperjurcenoks)
Assigned to: Nobody/Anonymous (nobody)
Summary: Non-blocking Socket Server

Initial Comment:
Changed the included Python 2.3.3 SocketServer.py 
to be non-blocking.

I have made a web-server on BaseHTTPServer, but the 
server could get shot down externally by sending 
malformed request. Making it very Easy to Perform a 
Denial of Service.

The problem also exists in "Module Docs" web-server

To experience problem run Module Docs, and verify that 
web-server is working

telnet to webserver (telnet 127.0.0.1 7464#)
type "GET /\r"

access any web-page on web-server and notice how it 
is hung.

Replace existing SocketServer.py with included 
SocketServer.py and re-test noticing that the problem 
is gone.



----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2005-02-24 20:59

Message:
Logged In: YES 
user_id=21627

I agree with Irmen's review. The BaseHTTPServer is
deliberately single-threaded. If you want a threaded server,
use SocketServer.ThreadingMixIn.

----------------------------------------------------------------------

Comment By: Irmen de Jong (irmen)
Date: 2005-01-16 16:23

Message:
Logged In: YES 
user_id=129426

There's nothing wrong with the default socket server.
It is blocking by design.
The module provides a few mixins that change the way the
requests are handled (see mmangino's comment)
Making it threaded by default wouldn't work because not all
systems support threading. That's why there is also the
forking mixin.


----------------------------------------------------------------------

Comment By: Mike Mangino (mmangino)
Date: 2004-07-13 21:46

Message:
Logged In: YES 
user_id=74879

Actually, forget the previous request. The better change
would be for you to create a ThreadedHTTPServer that
inherits from SocketServer.ThreadingTCPServer, i.e. you
could use

class ThreadingHTTPServer(SocketServer.ThreadingTCPServer):

    allow_reuse_address = 1    # Seems to make sense in
testing environment

    def server_bind(self):
        """Override server_bind to store the server name."""
        SocketServer.TCPServer.server_bind(self)
        host, port = self.socket.getsockname()[:2]
        self.server_name = socket.getfqdn(host)
        self.server_port = port


And then start the server with 

httpd = ThreadingHTTPServer(server_address,handler)



----------------------------------------------------------------------

Comment By: Mike Mangino (mmangino)
Date: 2004-07-13 21:21

Message:
Logged In: YES 
user_id=74879

Can you post a diff for this to make it easier to understand
what has changed?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=946207&group_id=5470


More information about the Patches mailing list