This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Non-blocking Socket Server
Type: Stage:
Components: Extension Modules Versions: Python 2.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: irmen, jesperjurcenoks, loewis, mmangino
Priority: normal Keywords: patch

Created on 2004-05-02 02:45 by jesperjurcenoks, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
SocketServer.py jesperjurcenoks, 2004-05-02 02:45 Modified 2.3.3 SocketServer.py non-blocking
Messages (5)
msg45905 - (view) Author: Jesper ´JJ´ Jurcenoks (jesperjurcenoks) Date: 2004-05-02 02:45
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.

msg45906 - (view) Author: Mike Mangino (mmangino) Date: 2004-07-13 19:21
Logged In: YES 
user_id=74879

Can you post a diff for this to make it easier to understand
what has changed?
msg45907 - (view) Author: Mike Mangino (mmangino) Date: 2004-07-13 19:46
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)

msg45908 - (view) Author: Irmen de Jong (irmen) (Python triager) Date: 2005-01-16 15:23
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.
msg45909 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2005-02-24 19:59
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.
History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40208
2004-05-02 02:45:23jesperjurcenokscreate