X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=1.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org X-Spam-Score: -4.389 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: Possible pipe(2) bug Date: Mon, 9 Aug 2010 19:56:25 +0200 Message-ID: In-Reply-To: <20100809170129.GA5254@ednor.casa.cgf.cx> References: <20100809170129 DOT GA5254 AT ednor DOT casa DOT cgf DOT cx> From: "Bert Belder" To: X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On Mon, Aug 09, 2010 at 07:01PM +0200, Christopher Faylor wrote: > On Mon, Aug 09, 2010 at 03:00:03AM +0200, Bert Belder wrote: > >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=3D(3, 4), pipe2=3D(5, 6), pipe3=3D(7, 8) > >? ??0 closed: pipe1[0]=3D3, pipe2[1]=3D6, pipe3[1]=3D8 > >? ??1 opened: pipe1=3D(3, 6), pipe2=3D(8, 9), pipe3=3D(10, 11) > >? ??1 closed: pipe1[0]=3D3, pipe2[1]=3D9, pipe3[1]=3D11 > >? ??2 opened: pipe1=3D(3, 9), pipe2=3D(11, 12), pipe3=3D(13, 14) > >? ??2 closed: pipe1[0]=3D3, pipe2[1]=3D12, pipe3[1]=3D14 > >??? ... > >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=3D(3, 282), pipe2=3D(284, 285), pipe3=3D(286, 287) > >??? 93 closed: pipe1[0]=3D3, pipe2[1]=3D285, pipe3[1]=3D287 > >??? 94 opened: pipe1=3D(3, 285), pipe2=3D(287, 288), pipe3=3D(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? >=20 > Nope. It was a very long-standing Cygwin bug. The error occurred when > Cygwin extended the size of its fd table. When that happened the the > internal information for the fd of the [0] element to the pipe() call > would never be filled out. If you attempted to use it you'd probably > get an EBADF. And, since cygwin thought it wasn't used it would > present > it to your program again. It's hard to believe that this hasn't shown > up before. >=20 > This should be fixed in the next snapshot, which is building now. An EBADF error followed by a crash was actually the problem I originally ran into. Using the latest snapshot DLL indeed solves my problem, thanks for fixing it. - Bert -- 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