Edgewall Software
Modify

Ticket #2052 (closed defect: fixed)

Opened 6 years ago

Last modified 5 years ago

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

Reported by: Juanma Barranquero Owned by: mgood
Priority: low Milestone: 0.9
Component: general Version: devel
Severity: normal Keywords: hooks windows
Cc: gytis@…
Release Notes:
API 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

Change History

comment:1 Changed 6 years ago by anonymous

  • 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 Changed 6 years ago by cboos

  • Milestone set to 0.9
  • Owner changed from jonas to cboos
  • Status changed from new to assigned

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 Changed 6 years ago by Juanma Barranquero

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 Changed 6 years ago by anonymous

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

comment:5 Changed 6 years ago by cmlenz

(Previous comment by me, sorry)

comment:6 Changed 6 years ago by mgood

  • Owner changed from cboos to mgood
  • Status changed from assigned to new

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 Changed 6 years ago by mgood

  • Resolution set to fixed
  • Status changed from new to closed

Ok, this should be fixed in [2260]

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from mgood. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.