[New-bugs-announce] [issue5715] listen socket close in SocketServer.ForkingMixIn.process_request()
Donghyun Kim
report at bugs.python.org
Tue Apr 7 02:30:50 CEST 2009
New submission from Donghyun Kim <uryan003 at gmail.com>:
During implement simple forking TCP server, I got the hang-up child
process binding listen socket which caused parent(listen/accept)
restarting failed. (port in use)
Because child process does something with connected socket, there's no
need to bind listen socket in child process.
(finish_request() calls RequestHandlerClass with connected socket(=request))
Simply add self.socket.close() in the beginning of forked child process.
SocketServer.ForkingMixIn :
def process_request(self, request, client_address):
"""Fork a new subprocess to process the request."""
self.collect_children()
pid = os.fork()
if pid:
# Parent process
if self.active_children is None:
self.active_children = []
self.active_children.append(pid)
self.close_request(request)
return
else:
# Child process.
# This must never return, hence os._exit()!
self.socket.close() # close parent's listen socket in child
try:
self.finish_request(request, client_address)
os._exit(0)
except:
try:
self.handle_error(request, client_address)
finally:
os._exit(1)
----------
components: Library (Lib)
messages: 85680
nosy: ryan003
severity: normal
status: open
title: listen socket close in SocketServer.ForkingMixIn.process_request()
type: behavior
versions: Python 2.4, Python 2.6, Python 3.0
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5715>
_______________________________________
More information about the New-bugs-announce
mailing list