Opened 17 years ago
Closed 17 years ago
#10117 closed (duplicate)
Test server sometimes causes 'Connection reset by peer' when retrieving POST data
| Reported by: | Almad | Owned by: | nobody |
|---|---|---|---|
| Component: | HTTP handling | Version: | 1.0 |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
When I create a view that returns 401 Unauthorized:
from django.http import HttpResponse
class HttpResponseNotAuthorized(HttpResponse):
status_code = 401
def return_not_authorized(request):
return HttpResponseNotAuthorized("401 Not Authorized")
and I wan't to POST some data using urllib2:
for i in xrange(1, 10):
response = urllib2.urlopen(url='http://%(host)s:%(port)s/return_not_authorized/' % {
'host' : 'localhost',
'port' : 8000
},
data='data')
I non-deterministically (thus the xrange cycle) get 'Connection reset by peer':
File "//usr/lib/python2.5/urllib2.py", line 124, in urlopen
return _opener.open(url, data)
File "//usr/lib/python2.5/urllib2.py", line 381, in open
response = self._open(req, data)
File "//usr/lib/python2.5/urllib2.py", line 399, in _open
'_open', req)
File "//usr/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "//usr/lib/python2.5/urllib2.py", line 1107, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "//usr/lib/python2.5/urllib2.py", line 1082, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error (104, 'Connection reset by peer')>
Tested on both 1.0 and SVN HEAD. Send agains server run by ./manage.py runserver.
Change History (6)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
ramiro: Problem is that mostly You get error on first request (i.e. no loop needed)...
comment:3 by , 17 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
After some investigation, it probably is a duplicate to #3357. Damn.
comment:4 by , 17 years ago
Looks like your problem isn't that the dev server is single threaded, but it could be a bug in wsgiref:
http://stackoverflow.com/questions/383738/104-connection-reset-by-peer-socket-error-or-when-does-closing-a-socket-result
comment:5 by , 17 years ago
| Resolution: | duplicate |
|---|---|
| Status: | closed → reopened |
OK, I'll reopen it for reference.
comment:6 by , 17 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | reopened → closed |
No, this is indeed a duplicate of #3357.
What happens if you insert a delay in the loop between requests?, remember the Django development server is single-threaded.