Code

Opened 5 years ago

Closed 5 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: UI/UX:

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.

Attachments (0)

Change History (6)

comment:1 Changed 5 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

What happens if you insert a delay in the loop between requests?, remember the Django development server is single-threaded.

comment:2 Changed 5 years ago by Almad

ramiro: Problem is that mostly You get error on first request (i.e. no loop needed)...

comment:3 Changed 5 years ago by Almad

  • Resolution set to duplicate
  • Status changed from new to closed

After some investigation, it probably is a duplicate to #3357. Damn.

comment:4 Changed 5 years ago by mawe

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 Changed 5 years ago by Almad

  • Resolution duplicate deleted
  • Status changed from closed to reopened

OK, I'll reopen it for reference.

comment:6 Changed 5 years ago by jacob

  • Resolution set to duplicate
  • Status changed from reopened to closed

No, this is indeed a duplicate of #3357.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.