[Python-bugs-list] [ python-Bugs-419873 ] ThreadingTCPServer invalidating sockets

noreply@sourceforge.net noreply@sourceforge.net
Tue, 10 Jul 2001 05:03:18 -0700


Bugs item #419873, was opened at 2001-04-28 16:22
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=419873&group_id=5470

>Category: Python Library
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Guido van Rossum (gvanrossum)
Summary: ThreadingTCPServer invalidating sockets

Initial Comment:
running this:
import SocketServer

class TestServer(SocketServer.ThreadingTCPServer):
    def __init__(self, server_address,
RequestHandlerClass):
        SocketServer.ThreadingTCPServer.__init__(self,
server_address, RequestHandlerClass)
        self.quit = 0

    def process_request(self, request, client_address):
        print 'socket in process_request = %s' % request
        print 'id(socket) in process_request = %d' %
id(request)
       
SocketServer.ThreadingTCPServer.process_request(self,
request, client_address)

    def finish_request(self, request, client_address):
        print 'socket in finish_request = %s' % request
        print 'id(socket) in finish_request = %d' %
id(request)
        self.RequestHandlerClass(request,
client_address, self)
    
    def get_request(self):
        conn, addr = self.socket.accept()
        print 'socket in get_request = %s' % conn
        print 'id(socket) in get_request = %d' % id(conn)
        return conn,addr

if __name__ == '__main__':
    s = TestServer(('',9950),
SocketServer.BaseRequestHandler)
    s.handle_request()
    s.server_close()

results in the following output (when connected to
remotely):

socket in get_request = <socket object, fd=4, family=2,
type=1, protocol=0>
id(socket) in get_request = 135335216
socket in process_request = <socket object, fd=4,
family=2, type=1, protocol=0>
id(socket) in process_request = 135335216
socket in finish_request = <socket object, fd=-1,
family=2, type=1, protocol=0>
id(socket) in finish_request = 135335216

between in the thread-creation in process_request, the
socket's fd changes to -1.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-07-10 04:58

Message:
Logged In: YES 
user_id=6380

I've produced a proper fix for this.  Check out
SocketServer.py from the CVS.


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

Comment By: Nobody/Anonymous (nobody)
Date: 2001-05-04 14:10

Message:
Logged In: NO 

Thanks, that solves the problem.

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

Comment By: Jon Riehl (jriehl)
Date: 2001-05-01 14:25

Message:
Logged In: YES 
user_id=22448

See comments for bug #417845.
BaseServer.handle_request() potentially (more like
consistently) calls close_request() before the thread spun
in process_request() is able to complete.  A work around is
shown in bug #417845 (overload close_request() to do nothing
instead of closing the socket.)

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

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=419873&group_id=5470