[Django] #31091: ConnectionResetError: [Errno 104] Connection reset by peer with a simple GET call

1,254 views
Skip to first unread message

Django

unread,
Dec 14, 2019, 6:34:19 PM12/14/19
to django-...@googlegroups.com
#31091: ConnectionResetError: [Errno 104] Connection reset by peer with a simple
GET call
-----------------------------------------+------------------------
Reporter: aleaforny | Owner: nobody
Type: Bug | Status: new
Component: HTTP handling | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Hello,

I have this pretty simple GET api method (I use djangorestframework, but
the issue is still related to Django itself, see all my explanations):


{{{
from rest_framework import generics, status
from rest_framework.response import Response
from django.conf import settings

class Monitoring(generics.RetrieveAPIView):
def retrieve(self, request, *args, **kwargs):
return Response({
"app_build": settings.APP_BUILD_NUMBER,
}, status=status.HTTP_200_OK
)
}}}

I was using Django **Version 2.1.1**, everything was working perfectly
fine.

Then, I upgraded to version **Django 2.2.8**, and I suddenly get the
following error (for all my API call, but I took the simplest as an
example) :


{{{
[14/Dec/2019 23:18:29] "GET /monitoring HTTP/1.1" 200 38
----------------------------------------
Exception happened during processing of request from ('x.y.z.x', 53609)
Traceback (most recent call last):
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/socketserver.py",
line 654, in process_request_thread
self.finish_request(request, client_address)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/socketserver.py",
line 364, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/socketserver.py",
line 724, in __init__
self.handle()
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-
packages/django/core/servers/basehttp.py", line 153, in handle
self.handle_one_request()
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-
packages/django/core/servers/basehttp.py", line 161, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/socket.py", line 586,
in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
----------------------------------------
}}}

FYI, I'm using **Python 2.6.9** version

By the way, these APIs are sending me the response as expected, these
errors are just printed on Django console, so I guess it's not critical
nor preventing Django to work as expected, but it's still annoying to get
these errors everytime now.

I just did one thing: Tried different versions of Django (using pip3.6),
and here the result I got :
- **Django 2.1.1:** Working as expected
- **Django 2.1.3:** Working as expected
- **Django 2.1.4:** Error
- **Django 2.1.5:** Error
- **Django 2.1.15:** Error
- **Django 2.2.0:** Error
- **Django 2.2.8:** Error

So I guess something happened between Django 2.1.3 and 2.1.4 but can't
figure what.

Thanks for the help!
Kindly

--
Ticket URL: <https://code.djangoproject.com/ticket/31091>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 16, 2019, 2:52:05 AM12/16/19
to django-...@googlegroups.com
#31091: ConnectionResetError: [Errno 104] Connection reset by peer with a simple
GET call.
-------------------------------------+-------------------------------------
Reporter: Baptiste | Owner: nobody
Vandenborght |
Type: Bug | Status: closed
Component: HTTP handling | Version: master
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* cc: Florian Apolloner (added)
* version: 2.2 => master
* resolution: => wontfix


Old description:

New description:

Hello,

--

Comment:

Thanks for this report, however I cannot reproduce this issue with Python
3.6.9 and Django 2.2.8.

This can be a side effect of 934acf1126995f6e6ccba5947ec8f7561633c27f
(ticket #29849), see a commit message:
> The combination of those two fixes resulted in yet another problem:
> HTTP/1.1 by default allows a client to assume that keep-alive is
> supported unless the server disables it via 'Connection: close' -- see
> RFC2616 8.1.2.1 for details on persistent connection negotiation. Now if
> the client receives a response from Django without 'Connection: close'
> and immediately sends a new request (on the same tcp connection) before
> our server closes the tcp connection, it will error out at some point
> because the connection does get closed a few milli seconds later.

but I don't think that there is anything we can improve in Django.

--
Ticket URL: <https://code.djangoproject.com/ticket/31091#comment:1>

Django

unread,
Dec 16, 2019, 2:53:46 AM12/16/19
to django-...@googlegroups.com
#31091: ConnectionResetError: [Errno 104] Connection reset by peer with a simple
GET call.
-------------------------------------+-------------------------------------
Reporter: Baptiste | Owner: nobody
Vandenborght |
Type: Bug | Status: closed
Component: HTTP handling | Version: master
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* resolution: wontfix => invalid


--
Ticket URL: <https://code.djangoproject.com/ticket/31091#comment:2>

Django

unread,
Jan 21, 2020, 11:04:08 AM1/21/20
to django-...@googlegroups.com
#31091: ConnectionResetError: [Errno 104] Connection reset by peer with a simple
GET call.
-------------------------------------+-------------------------------------
Reporter: Baptiste | Owner: nobody
VANDENBORGHT |

Type: Bug | Status: closed
Component: HTTP handling | Version: master
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Baptiste VANDENBORGHT):

Replying to [comment:1 felixxm]:


> Thanks for this report, however I cannot reproduce this issue with
Python 3.6.9 and Django 2.2.8.
>
> This can be a side effect of 934acf1126995f6e6ccba5947ec8f7561633c27f
(ticket #29849), see a commit message:
> > The combination of those two fixes resulted in yet another problem:
> > HTTP/1.1 by default allows a client to assume that keep-alive is
> > supported unless the server disables it via 'Connection: close' -- see
> > RFC2616 8.1.2.1 for details on persistent connection negotiation. Now
if
> > the client receives a response from Django without 'Connection: close'
> > and immediately sends a new request (on the same tcp connection)
before
> > our server closes the tcp connection, it will error out at some point
> > because the connection does get closed a few milli seconds later.
>
> but I don't think that there is anything we can improve in Django.


Good shot! That's nothing to improve in Django directly, indeed!

I've just added the header Connection: close and it fixed it (for those
who may encounter this issue as well)

Thanks again for your help

--
Ticket URL: <https://code.djangoproject.com/ticket/31091#comment:3>

Reply all
Reply to author
Forward
0 new messages