Possible pipe(2) bug

Bert Belder H.Belder@student.TUDelft.NL
Mon Aug 9 01:00:00 GMT 2010


I think the pipe(2) implementation may have a bug. 

The pipe function creates a pipe and returns two file descriptors (which are just numbers), one for reading and one for writing. However sometimes (but rarely) two subsequent calls to the pipe function returns the same file descriptor twice. That is normal when a file descriptor 'number' is re-used after being closed first, but otherwise it is wrong. To demonstrate the problem I wrote a simple program (attached as test.c) that does the following:

1. Create three pipes, so we get 6 file descriptors
2. (dump the FD's we got)
3. Close 3 of the 6 file descriptors
4. (Dump the FD's that were closed)
5. Repeat steps 1-4 a 100 times 

The first three rounds give sound results:
    0 opened: pipe1=(3, 4), pipe2=(5, 6), pipe3=(7, 8)
    0 closed: pipe1[0]=3, pipe2[1]=6, pipe3[1]=8
    1 opened: pipe1=(3, 6), pipe2=(8, 9), pipe3=(10, 11)
    1 closed: pipe1[0]=3, pipe2[1]=9, pipe3[1]=11
    2 opened: pipe1=(3, 9), pipe2=(11, 12), pipe3=(13, 14)
    2 closed: pipe1[0]=3, pipe2[1]=12, pipe3[1]=14
    ...
As can be seen the FD's that were closed are re-used next round. Perfectly fine.

But then suddenly at round 94...
    93 opened: pipe1=(3, 282), pipe2=(284, 285), pipe3=(286, 287)
    93 closed: pipe1[0]=3, pipe2[1]=285, pipe3[1]=287
    94 opened: pipe1=(3, 285), pipe2=(287, 288), pipe3=(287, 289)  <- !!!!!!!!!!!!
File descriptor 287 is issued twice! 

I think this is a bug. It actually causes problems under certain circumstances when running a Cygwin build of nodejs (http://nodejs.org).
Or am I just doing something stupid?

Thanks for your time
- Bert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygcheck.out
Type: application/octet-stream
Size: 27712 bytes
Desc: cygcheck.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100809/1e97ad86/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: application/octet-stream
Size: 924 bytes
Desc: test.c
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100809/1e97ad86/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.out
Type: application/octet-stream
Size: 11070 bytes
Desc: test.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100809/1e97ad86/attachment-0002.obj>
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list