Edgewall Software
Modify

Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#2052 closed defect (fixed)

"Bad file descriptor" error setting binary I/O on Windows

Reported by: Juanma Barranquero Owned by: Matthew Good
Priority: low Milestone: 0.9
Component: general Version: devel
Severity: normal Keywords: hooks windows
Cc: gytis@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

(This has been discussed on the mailing list, but AFAICS there's no ticket for it).

The following code from env.py originates in changes [412:413], commited to fix #244:

try: # Use binary I/O on Windows
    import msvcrt, sys
    msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
except ImportError:
    pass

However, it has the side effect that it bombs out with

   File "C:\bin\python\lib\site-packages\trac\env.py", line 70, in __init__
    msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
 IOError: [Errno 9] Bad file descriptor

on some cases (Windows hooks, running as a service, etc.), as apparently there are no stdin/stdout filehandles available.

Attachments (0)

Change History (7)

comment:1 by anonymous, 19 years ago

Cc: gytis@… added

I had this problem with SVN commit hooks, when using mod_dav_svn. The solution (i would rather call it a hack) was to open temporary files for stdin and stdout.

comment:2 by Christian Boos, 19 years ago

Milestone: 0.9
Owner: changed from Jonas Borgström to Christian Boos
Status: newassigned

Would trapping the IOError be OK?

- except ImportError:
+ except (ImportError, IOError, ValueError):

ValueError added for good mesure, it's what one gets if the files are closed.

comment:3 by Juanma Barranquero, 19 years ago

Trapping IOError is what I do, and it works for my use case (calling trac-post-commit-hook from the post-commit hook). I don't know whether this fix works for the other use cases (but presumably it will, at least on the running-as-service case, where standard handles are not needed or used).

comment:4 by anonymous, 19 years ago

Wouldn't it be better to do this whole binary-io-on-win32 thing in the CGI front-end?

comment:5 by Christopher Lenz, 19 years ago

(Previous comment by me, sorry)

comment:6 by Matthew Good, 19 years ago

Owner: changed from Christian Boos to Matthew Good
Status: assignednew

Since this involves similar issues with the stdin/stdout mode to #2066 I'll combine the two to provide a single method in the CGI front-end to make sure the modes are set correctly for the applicable platform.

comment:7 by Matthew Good, 19 years ago

Resolution: fixed
Status: newclosed

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.