Edgewall Software

Opened 21 months ago

Closed 21 months ago

Last modified 21 months ago

#13492 closed defect (fixed)

Uploading an attachment fails with "AssertionError: write() before start_response()" (mod_fcgid)

Reported by: arroz Owned by: Jun Omae
Priority: normal Milestone: 1.5.4
Component: web frontend Version: 1.5.3
Severity: critical Keywords: fcgi, attachment
Cc: miguel.arroz@… Branch: trunk
Release Notes:

Fix internal server error when uploading files using fcgi.

API Changes:
Internal Changes:


Running Trac 1.5.4.dev0 (0182158c5cb676af5b40cf1714c3d29c28a9d632 from the git repository). Not sure if the problem actually happens in 1.5.3, I need to be on trunk due to a different issue, so consider this 1.5dev (that version isn't available in the list).

When uploading an attachment to a ticket, I get the following error on the browser. This doesn't seem to depend on either the name or size of the attachment (a one byte file with a name with no special chars or spaces triggers the problem).

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/trac/web/_fcgi.py", line 572, in run
    protocolStatus, appStatus = self.server.handler(self)
  File "/usr/local/lib/python3.9/site-packages/trac/web/_fcgi.py", line 1250, in handler
    write(b'') # in case body was empty
  File "/usr/local/lib/python3.9/site-packages/trac/web/_fcgi.py", line 1203, in write
    assert headers_set, 'write() before start_response()'
AssertionError: write() before start_response()

Attachments (0)

Change History (5)

comment:1 by Miguel Arroz <miguel.arroz@…>, 21 months ago

Cc: miguel.arroz@… added

comment:2 by Jun Omae, 21 months ago

Component: attachmentweb frontend
Keywords: fcgi added
Milestone: 1.5.4
Owner: set to Jun Omae
Status: newassigned

Thanks for the report! I get the following traceback on reproducing the issue:

10:54:36 Trac[main] ERROR: [] Internal Server Error: <RequestWithSession "POST '/attachment/ticket/102'">, referrer ''
Traceback (most recent call last):
  File "/vol/src/tracdev/git/trac/web/main.py", line 610, in dispatch_request
  File "/vol/src/tracdev/git/trac/web/main.py", line 302, in dispatch
    raise e
  File "/vol/src/tracdev/git/trac/web/main.py", line 207, in dispatch
    if handler.match_request(req):
  File "/vol/src/tracdev/git/trac/attachment.py", line 168, in match_request
    req.args['realm'] = realm
  File "/vol/src/tracdev/git/trac/web/api.py", line 569, in __getattr__
    value = self.callbacks[name](self)
  File "/vol/src/tracdev/git/trac/web/api.py", line 551, in <lambda>
    'args': lambda req: arg_list_to_args(req.arg_list),
  File "/vol/src/tracdev/git/trac/web/api.py", line 569, in __getattr__
    value = self.callbacks[name](self)
  File "/vol/src/tracdev/git/trac/web/api.py", line 943, in _parse_arg_list
    fs = _FieldStorage(fp, environ=self.environ,
  File "/usr/lib/python3.9/cgi.py", line 480, in __init__
    self.read_multi(environ, keep_blank_values, strict_parsing)
  File "/vol/src/tracdev/git/trac/web/api.py", line 272, in read_multi
    cgi.FieldStorage.read_multi(self, *args, **kwargs)
  File "/usr/lib/python3.9/cgi.py", line 617, in read_multi
    first_line = self.fp.readline() # bytes
  File "/vol/src/tracdev/git/trac/web/_fcgi.py", line 185, in readline
    i = self._buf.find('\n', self._pos)
TypeError: argument should be integer or bytes-like object, not 'str'

I've fixed fcgi issue #13403 but the fix was incomplete.

Could you please try the following patch?

  • trac/web/_fcgi.py

    diff --git a/trac/web/_fcgi.py b/trac/web/_fcgi.py
    index 3e34846fd..0868328ac 100644
    a b class InputStream(object):  
    182182                self._buf += _bytes_join(self._bufList)
    183183                self._bufList = []
    184184            # Find newline.
    185             i = self._buf.find('\n', self._pos)
     185            i = self._buf.find(b'\n', self._pos)
    186186            if i < 0:
    187187                # Not found?
    188188                if self._eof:

comment:3 by Miguel Arroz <miguel.arroz@…>, 21 months ago

Thanks for the super quick feedback.

Yeah, that patch works perfectly! I can now upload attachments without issues. Thank you! 🙏 Sorry for not including the more detailed trace originally.

comment:4 by Jun Omae, 21 months ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed in [17604]. Thanks for the reporting, again!

comment:5 by figaro, 21 months ago

#13496 closed as a duplicate.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae 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.