Received: by 10.91.182.8 with SMTP id j8mr119387agp.4.1295401502518; Tue, 18 Jan 2011 17:45:02 -0800 (PST) X-BeenThere: emm-ruby@googlegroups.com Received: by 10.90.6.21 with SMTP id 21ls273321agf.5.p; Tue, 18 Jan 2011 17:45:01 -0800 (PST) MIME-Version: 1.0 Received: by 10.90.95.14 with SMTP id s14mr9464agb.5.1295401501165; Tue, 18 Jan 2011 17:45:01 -0800 (PST) Received: by j32g2000prh.googlegroups.com with HTTP; Tue, 18 Jan 2011 17:45:01 -0800 (PST) Date: Tue, 18 Jan 2011 17:45:01 -0800 (PST) In-Reply-To: <2054bd51-19b2-4383-ace5-2c4efe6b9507@o11g2000prf.googlegroups.com> X-IP: 72.215.191.218 References: <2054bd51-19b2-4383-ace5-2c4efe6b9507@o11g2000prf.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13,gzip(gfe) Message-ID: <8733d0f9-5711-41f2-baaa-70d7f0cabc0c@j32g2000prh.googlegroups.com> Subject: Re: Ruby Tempfile can cause unexpected infinite loop in REE 1.8.7 From: WU Chehai To: Ruby Enterprise Edition Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Actually, regular Ruby 1.8.7-p330 does not has this issue. The regular Ruby 1.8.7 finalizes objects every time a node is evaled if some conditions are met, so the temp file object (temp) is finalized before the thread exists. Everything should be fine. Therefore, this is a bug in current REE 1.8.7 On Jan 17, 4:34=A0pm, WU Chehai wrote: > Hi, all > > The following code ends up an infinite loop > > require "tempfile" > GC.stress =3D true > t =3D Thread.new do > =A0 temp =3D Tempfile.new("tmp") > =A0 temp << "something" > =A0 temp =3D nil > =A0 h =3D Hash.new > end > t.join > > Our analysis shows that there is a race condition in REE 1.8.7: > > - When a thread finishes running, REE/Ruby dequeues it > (rb_thread_remove) =A0from the global thread list and calls > rb_thread_schedule in order to schedule another thread to run. > > - rb_thread_schedule invokes =A0rb_gc_finalize_deferred before > scheduling another thread. > > - rb_gc_finalize calls finalizer on Ruby Tempfile object. The > finalizer closes a file descriptor by calling rb_thread_fd_close > > - rb_thread_fd_close has a loop to iterate over all threads. > > - However, the current thread is already dequeued (it points to other > threads, but no threads point back to it), so the loop is actually an > infinite loop. > > We believe this issue also exists in regular Ruby 1.8.7, but we cannot > reproduce it. Is this a bug in REE 1.8.7? >