Opened 4 years ago
Closed 4 years ago
#33115 closed Bug (duplicate)
Connection issue after a HEAD is used
| Reported by: | Dave Johansen | Owned by: | nobody |
|---|---|---|---|
| Component: | HTTP handling | Version: | 2.2 |
| Severity: | Normal | Keywords: | keepalive |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
We noticed that monitoring checks using HEAD were causing ConnectionResetError issues in our logs. We believe that this may be causing issues with some other requests, but haven't been able to verify that yet. However, there's a simple way to reproduce this issue. Simply create a new project and run it using the instructions from the tutorial and then run a command like this curl -I http://localhost:8000/ http://localhost:8000/ or run a Python script like this:
import logging
import requests
logging.basicConfig(level=logging.DEBUG)
s = requests.Session()
r = s.head('http://localhost:8000/')
print(r.status_code, r.text)
r = s.head('http://localhost:8000/')
print(r.status_code, r.text)
And you'll notice an output like this:
16/Sep/2021 16:02:17] "HEAD / HTTP/1.1" 200 16348
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 44808)
Traceback (most recent call last):
File "/usr/local/lib/python3.7/socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "/usr/local/lib/python3.7/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/lib/python3.7/socketserver.py", line 720, in __init__
self.handle()
File "/usr/local/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 171, in handle
self.handle_one_request()
File "/usr/local/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 179, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "/usr/local/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
----------------------------------------
[16/Sep/2021 16:02:18] "HEAD / HTTP/1.1" 200 16348
Or with 3.2, an output like this:
[16/Sep/2021 23:31:37] "HEAD / HTTP/1.1" 200 10697
[16/Sep/2021 23:31:37,819] - Broken pipe from ('127.0.0.1', 46600)
[16/Sep/2021 23:31:45] "HEAD / HTTP/1.1" 200 10697
Change History (1)
comment:1 by , 4 years ago
| Component: | Core (Other) → HTTP handling |
|---|---|
| Resolution: | → duplicate |
| Status: | new → closed |
It's a duplicate of #28054 and #29343, the proposed PR fixes this issue for me.