Edgewall Software
Modify

Opened 19 years ago

Closed 19 years ago

Last modified 2 years ago

#2066 closed defect (fixed)

[patch] EAGAIN error when writing to stdout

Reported by: nielsen@… Owned by: Matthew Good
Priority: normal Milestone:
Component: general Version: 0.8.4
Severity: major Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

On certain systems (running FreeBSD 5.4, python 2.3 etc…) I get this error all over the place:

Oops...
Trac detected an internal error:

[Errno 35] Resource temporarily unavailable

If you think this really should work and you can reproduce it. Then you should consider to report this problem to the Trac team.

Go to http://trac.edgewall.com/ and create a new ticket where you describe the problem, how to reproduce it. Don't forget to include the python traceback found below.

TracGuide — The Trac User and Administration Guide
Python traceback

Traceback (most recent call last):
  File "/usr/local/lib/python2.3/site-packages/trac/core.py", line 525, in cgi_start
    real_cgi_start()
  File "/usr/local/lib/python2.3/site-packages/trac/core.py", line 520, in real_cgi_start
    dispatch_request(path_info, args, req, env)
  File "/usr/local/lib/python2.3/site-packages/trac/core.py", line 435, in dispatch_request
    module.run()
  File "/usr/local/lib/python2.3/site-packages/trac/Module.py", line 46, in run
    disp()
  File "/usr/local/lib/python2.3/site-packages/trac/Module.py", line 81, in display
    self.req.display(self.template_name)
  File "/usr/local/lib/python2.3/site-packages/trac/core.py", line 331, in display
    self.write(data)
  File "/usr/local/lib/python2.3/site-packages/trac/core.py", line 378, in write
    return sys.stdout.write(data)
IOError: [Errno 35] Resource temporarily unavailable

The EAGAIN error should be caught. I'll attach a patch which fixes this problem.

Attachments (1)

trac-eagain.patch (499 bytes ) - added by nielsen@… 19 years ago.
Patch which fixes the issue.

Download all attachments as: .zip

Change History (6)

by nielsen@…, 19 years ago

Attachment: trac-eagain.patch added

Patch which fixes the issue.

comment:1 by Matthew Good, 19 years ago

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

Well, apparently FreeBSD's threading library automatically sets stdin and stdout to be non-blocking. I guess for C apps this wouldn't be a big deal since it'd only occur when you explicitly use threading, but since threading support in Python needs compiled in at the interpreter level this will always happen, regardless of whether the Python app itself is threaded.

Since CGI doesn't use threading, and the FastCGI or mod_python shouldn't be using stdout, I think that it would be sufficient for the CGI script to simply ensure that stdout is in blocking mode.

I believe that the following should do the trick, though I don't have a FreeBSD box to test it on:

  • cgi-bin/trac.cgi

    === cgi-bin/trac.cgi
    ==================================================================
     
    1515#
    1616# Author: Jonas Borgstr\uffffm <jonas@edgewall.com>
    1717
     18import fcntl
     19import os
     20import sys
     21
     22def make_blocking(fd):
     23    flags = fcntl.fcntl(fd, fcntl.F_GETFL)
     24    if flags & os.O_NONBLOCK:
     25        fcntl.fcntl(fd, fcntl.F_SETFL, flags & ~os.NONBLOCK)
     26
    1827try:
    1928    from trac.web import cgi_frontend
     29    make_blocking(sys.stdin.fileno())
     30    make_blocking(sys.stdout.fileno())
    2031    cgi_frontend.run()
    2132except Exception, e:
    2233    print 'Content-Type: text/plain\r\n\r\n',

comment:2 by nielsen@…, 19 years ago

The patch doesn't apply on 0.8.x but I added your function and calls to trac.cgi and tested it. And, yes, this fixes the problem, thanks.

There's just a small typo in the patch: The second 'NONBLOCK' should be 'O_NONBLOCK'.

comment:3 by Matthew Good, 19 years ago

Oops, I applied it locally, but since the sockets were already blocking on my machine it didn't run the line with the typo.

I'll combine these changes with the fixes for the stdin/stdout mode on Windows from #2052.

comment:4 by nielsen@…, 19 years ago

That's great. Thanks.

comment:5 by Matthew Good, 19 years ago

Resolution: fixed
Status: assignedclosed

Ok, this should be fixed in [2260]

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.