Edgewall Software
Modify

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#3619 closed defect (fixed)

using req.environ[wsgi.input].read() makes tracd connection stall

Reported by: trac@… Owned by: Matthew Good
Priority: normal Milestone: 0.10
Component: web frontend/tracd Version: devel
Severity: normal Keywords: needinfo
Cc: trac@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

When I run tracd and attempt to access a URI whose handler uses Request.environ['wsgi.input'].read(), that connection hangs until I cancel it. Attached is a testcase plugin and output log.

Attachments (3)

tracd_log (2.9 KB ) - added by trac@… 18 years ago.
command line output + tracd log output
trac-wsgi.input-testcase.tar.bz2 (630 bytes ) - added by trac@… 18 years ago.
testcase plugin source code; tested using r3640
request_read_fix.patch (628 bytes ) - added by trac@… 18 years ago.
fixes the call to get_header() in Request.read()

Download all attachments as: .zip

Change History (10)

by trac@…, 18 years ago

Attachment: tracd_log added

command line output + tracd log output

by trac@…, 18 years ago

testcase plugin source code; tested using r3640

in reply to:  description ; comment:1 by Matthew Good, 18 years ago

Resolution: invalid
Status: newclosed

Replying to trac@lazymalevolence.com:

When I run tracd and attempt to access a URI whose handler uses Request.environ['wsgi.input'].read(), that connection hangs until I cancel it. Attached is a testcase plugin and output log.

During the initialization of the Request object all the content of wsgi.input is read, so there will be nothing left to read in the request handler. For help developing a plugin check on the MailingList, since reading from wsgi.input is not the right way to get the data you need.

in reply to:  1 ; comment:2 by trac@…, 18 years ago

Resolution: invalid
Status: closedreopened

Replying to mgood:

Replying to trac@lazymalevolence.com:

When I run tracd and attempt to access a URI whose handler uses Request.environ['wsgi.input'].read(), that connection hangs until I cancel it. Attached is a testcase plugin and output log.

During the initialization of the Request object all the content of wsgi.input is read, so there will be nothing left to read in the request handler. For help developing a plugin check on the MailingList, since reading from wsgi.input is not the right way to get the data you need.

Firstly, based on reading the code in trac/web/api.py, it seems that the content of wsgi.input is read only if the Content-Type indicates that it is form data. I have been testing it when it is not either of those types. Secondly, I neglected to mention (i.e., forgot) that it works just fine when using a mod_python setup. In any case, the behavior of wsgi.input is inconsistent between web frontends, and this, at least, deserves to be looked at.

in reply to:  2 comment:3 by Matthew Good, 18 years ago

Keywords: needinfo added

Replying to trac@lazymalevolence.com:

Secondly, I neglected to mention (i.e., forgot) that it works just fine when using a mod_python setup. In any case, the behavior of wsgi.input is inconsistent between web frontends, and this, at least, deserves to be looked at.

Ah, yes I think that was necessary at least for the XML-RPC plugin to read the request body. Have you tried using req.read()? This will read from wsgi.input, but checks the "Content-Length" header for how many bytes to read.

comment:4 by trac@…, 18 years ago

Cc: trac@… added

This is what happens when I change the last line in my testcase from req.write(req.environ['wsgi.input'].read()) to req.write(req.read()) and attempt to access /null/testcase in the same fashion (still r3640):

2006-08-25 14:19:56,800 Trac[main] ERROR: get_header() takes exactly 2 arguments (3 given)
Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 335, in dispatch_request
    dispatcher.dispatch(req)
  File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 220, in dispatch
    resp = chosen_handler.process_request(req)
  File "build/bdist.linux-i686/egg/wsgi_input_testcase/__init__.py", line 12, in process_request
    # ;-)
  File "/usr/lib/python2.4/site-packages/trac/web/api.py", line 411, in read
    size = int(self.get_header('Content-Length', -1))
TypeError: get_header() takes exactly 2 arguments (3 given)

I assume that when Request.read() was written, Request.get_header() had a method signature similar to dict().get().

comment:5 by Matthew Good, 18 years ago

Owner: changed from Jonas Borgström to Matthew Good
Status: reopenednew

I'll look into this.

by trac@…, 18 years ago

Attachment: request_read_fix.patch added

fixes the call to get_header() in Request.read()

comment:6 by Matthew Good, 18 years ago

Milestone: 0.10
Status: newassigned

Ok, thanks for the patch.

comment:7 by Matthew Good, 18 years ago

Resolution: fixed
Status: assignedclosed

Ok, a small variant on that patch has been committed in r3746 along with unit tests.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Matthew Good.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Matthew Good to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.