#2066 closed defect (fixed)
[patch] EAGAIN error when writing to stdout
Reported by: | 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)
Change History (6)
by , 19 years ago
Attachment: | trac-eagain.patch added |
---|
comment:1 by , 19 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
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 ==================================================================
15 15 # 16 16 # Author: Jonas Borgstr\uffffm <jonas@edgewall.com> 17 17 18 import fcntl 19 import os 20 import sys 21 22 def 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 18 27 try: 19 28 from trac.web import cgi_frontend 29 make_blocking(sys.stdin.fileno()) 30 make_blocking(sys.stdout.fileno()) 20 31 cgi_frontend.run() 21 32 except Exception, e: 22 33 print 'Content-Type: text/plain\r\n\r\n',
comment:2 by , 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 , 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:5 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Ok, this should be fixed in [2260]
Patch which fixes the issue.