bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.37k stars 1.46k forks source link

"Connection reset by peer" #1208

Closed dbeecham closed 4 years ago

dbeecham commented 4 years ago
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 34152)
Traceback (most recent call last):
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 138, in run
    self.finish_response()
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 180, in finish_response
    self.write(data)
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 274, in write
    self.send_headers()
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 333, in send_headers
    self._write(bytes(self.headers))
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 453, in _write
    result = self.stdout.write(data)
  File "/usr/lib/python3.6/socketserver.py", line 803, in write
    self._sock.sendall(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 141, in run
    self.handle_error()
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 368, in handle_error
    self.finish_response()
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 180, in finish_response
    self.write(data)
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 274, in write
    self.send_headers()
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/socketserver.py", line 320, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 351, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
    self.handle()
  File "/usr/lib/python3.6/wsgiref/simple_server.py", line 133, in handle
    handler.run(self.server.get_app())
  File "/usr/lib/python3.6/wsgiref/handlers.py", line 144, in run
    self.close()
  File "/usr/lib/python3.6/wsgiref/simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------

I got this error when running

curl -vsfX PATCH -H "content-type: application/json" localhost:8080/hello/ok --data-ascii "{\"hello\":\"hi\"}"

against this server

#!/usr/bin/env python3

from bottle import route, run, template, debug, request, response, abort

@route('/hello/<id>', method='PATCH')
def patch_gateway(id):
    response.status = 404
    return 'nope'

run(host='0.0.0.0', port=8080)
v-python commented 4 years ago

I've experienced that same error sequence in using a more complex server from standard Windows browsers, on the Windows platform, and haven't a clue where to look to discover the problem. For me it is intermitant and doesn't seem to cause serious issues, something must retry.

But it looks like you get this on some Linux platform? Is it 100% reproducible? If so, this could be a great step towards understanding and solving the problem.

defnull commented 4 years ago

If that's a bug, then in python wsgiref, not in bottle. Not much we can do about that. Looks like the client disconnected too early (probably because of -f) and wsgiref failed to write the response to the socket, and then failed at handling that error. Bottle is no longer involved at that point.