SocketServer doesn't handle client disconnects properly.
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Python |
Fix Released
|
Unknown
|
|||
python2.7 (Ubuntu) |
Fix Released
|
Medium
|
Unassigned |
Bug Description
When dealing with a new connection, SocketServer.
class BaseRequestHandler:
def __init__(self, request, client_address, server):
< ... snip ... >
try:
finally:
The issue arises when a client disconnects suddenly during the self.handle() call. The handler may attempt to write data to the disconnected socket. This will cause an exception (which is correct), but somehow data will still be added to the connection's buffer and self.wfile.closed will be False! As a result, BaseRequestHand
-------
Exception happened during processing of request from ('127.0.0.1', 62718)
Traceback (most recent call last):
File "C:\Python27\
self.
File "C:\Python27\
self.
File "C:\Python27\
self.
File "C:\Python27\
self.finish()
File "C:\Python27\
self.
File "C:\Python27\
self.
error: [Errno 10053] An established connection was aborted by the software in your host machine
-------
I've provided a toy server below, you can reproduce the issue by submitting a request to it with curl and then immediately killing curl:
curl -d "test" http://
Toy server code:
=======
import BaseHTTPServer
import SocketServer
import time
class ThreadedHTTPSer
pass
class RequestHandler(
def do_POST(self):
try:
length = int(self.
request = self.rfile.
print "Sleeping. Kill the 'curl' command now."
time.
print "Woke up. You should see a stack trace from the problematic exception below."
print "Received POST: " + request
self.
self.
except Exception as e:
print "Exception: " + str(e) # <----- This exception is expected
httpd = ThreadedHTTPSer
httpd.serve_
httpd.server_
tags: | added: precise quantal |
Changed in python: | |
status: | Unknown → Fix Released |
Changed in python2.7 (Ubuntu): | |
status: | New → Triaged |
importance: | Undecided → Medium |
fixed in 14.04 LTS and later releases