Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Ruby Tempfile can cause unexpected infinite loop in REE 1.8.7

Received: by 10.236.180.33 with SMTP id i21mr15486683yhm.1.1334099287809;
        Tue, 10 Apr 2012 16:08:07 -0700 (PDT)
X-BeenThere: emm-ruby@googlegroups.com
Received: by 10.236.121.36 with SMTP id q24ls754877yhh.4.gmail; Tue, 10 Apr
 2012 16:08:07 -0700 (PDT)
Received: by 10.101.108.16 with SMTP id k16mr5251504anm.22.1334099287160;
        Tue, 10 Apr 2012 16:08:07 -0700 (PDT)
Received: by 10.101.108.16 with SMTP id k16mr5251503anm.22.1334099287130;
        Tue, 10 Apr 2012 16:08:07 -0700 (PDT)
Return-Path: <nate.westhei...@gmail.com>
Received: from mail-yw0-f50.google.com (mail-yw0-f50.google.com [209.85.213.50])
        by gmr-mx.google.com with ESMTPS id k4si656599yhm.3.2012.04.10.16.08.07
        (version=TLSv1/SSLv3 cipher=OTHER);
        Tue, 10 Apr 2012 16:08:07 -0700 (PDT)
Received-SPF: pass (google.com: domain of nate.westhei...@gmail.com designates 209.85.213.50 as permitted sender) client-ip=209.85.213.50;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of nate.westhei...@gmail.com designates 209.85.213.50 as permitted sender) smtp.mail=nate.westhei...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-yw0-f50.google.com with SMTP id j63so251274yhj.23
        for <emm-ruby@googlegroups.com>; Tue, 10 Apr 2012 16:08:07 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:in-reply-to:references:date:message-id:subject:from:to
         :content-type;
        bh=U3ASpJv3RAsJsnpGY4wb5axbeJoX+vfFj+ASmq6uafU=;
        b=ZAutuVPCQ54iqCDme72CAn29TuFjk5Ntud15ZtPMtNuQxJG+2jNZTpygPvsyiv2oIW
         Tr10lqfRUZWFitPABlK3EFfKyL399LdeSvvRRMRlvotSLAsppo/hDyuOEpq6LBzQ44Vf
         MWeuFY+1tPKQhA7DCezU25Y2pXSyluC8OEqoGkWPc8gH7erlMxzvLXT7RYR/jAqzalEt
         bmsLwupeTLsZlfQ1af99JCGQtHKCgf6b1R+ifP7kG1Y2vg75wU/Dkt0U0PzOWbqV9Keb
         ALzv9vJ+0RMH+IYwjRoWmelwB1ktrHjFdDaDeFSTuwgE4BvAxKUTPQYz+H4fcepVRAAd
         FjdA==
MIME-Version: 1.0
Received: by 10.101.3.16 with SMTP id f16mr3458933ani.60.1334099286984; Tue,
 10 Apr 2012 16:08:06 -0700 (PDT)
Received: by 10.236.25.33 with HTTP; Tue, 10 Apr 2012 16:08:06 -0700 (PDT)
In-Reply-To: <CABgnXpbiJx47eg22WHu1G2eU+RqNC9uo-JN92wd2=-NtgsD...@mail.gmail.com>
References: <2054bd51-19b2-4383-ace5-2c4efe6b9...@o11g2000prf.googlegroups.com>
	<8733d0f9-5711-41f2-baaa-70d7f0cab...@j32g2000prh.googlegroups.com>
	<CAE=PE6Rk45rua3NJt72UN6miveTQwxvoY5QAn9MFb26=eGB...@mail.gmail.com>
	<26b69247-eaa8-44ff-8eec-e64ecd25c...@t20g2000prf.googlegroups.com>
	<30627964.359.1334092502471.JavaMail.geo-discussion-forums@vbvi18>
	<CAHCobANa=bt9W3T6NM6R-mGHjvV9-S044wBhdCj=KP2tr+A...@mail.gmail.com>
	<CABgnXpbiJx47eg22WHu1G2eU+RqNC9uo-JN92wd2=-NtgsD...@mail.gmail.com>
Date: Tue, 10 Apr 2012 19:08:06 -0400
Message-ID: <CAGkDjQDZncRuM3sUk6Cjc_69+2G9eRbvFM5DQfjc0nXMRDH...@mail.gmail.com>
Subject: Re: Ruby Tempfile can cause unexpected infinite loop in REE 1.8.7
From: Nate Westheimer <nate.westhei...@gmail.com>
To: emm-ruby@googlegroups.com
Content-Type: multipart/alternative; boundary=0016368e2b4618886e04bd5b32b6

--0016368e2b4618886e04bd5b32b6
Content-Type: text/plain; charset=ISO-8859-1

Ahh, shoot. Thanks. Seems Google Groups had just appended a period to the
hyperlink in the archives. Thanks and sorry for the email clutter.
N

On Tue, Apr 10, 2012 at 7:04 PM, Michael Chletsos <mpchl...@gmail.com>wrote:

> take the period out of the link
>
> https://github.com/twitter/rubyenterpriseedition187-248/commit/83fc22
>
> On Tue, Apr 10, 2012 at 1:02 PM, Chehai WU <wuche...@gmail.com> wrote:
> > The link works for me.
> >
> > On Tue, Apr 10, 2012 at 2:15 PM, Nate Westheimer <
> nate.westhei...@gmail.com>
> > wrote:
> >>
> >> Hey All,
> >>
> >> That link to Twitter's GH is broken. Can anyone point me to a
> replacement
> >> for this?
> >>
> >> Thanks,
> >> Nate
> >>
> >>
> >> On Thursday, August 25, 2011 1:25:03 AM UTC-4, WU Chehai wrote:
> >>>
> >>> Thanks very much! We are going to use your patch.
> >>>
> >>> On Jul 29, 11:03 am, Evan Weaver <ewea...@gmail.com> wrote:
> >>> > We ran into this bug in Kiji and fixed it the following
> >>> > way:
> https://github.com/twitter/rubyenterpriseedition187-248/commit/83fc22...
> >>> >
> >>> > It was causing a horrible fault for us where the readfds for the curr
> >>> > thread would get nulled out; thus you wait on nothing for the full
> >>> > timeout (in Net::HTTP) in this case.
> >>> >
> >>> > REE also calls rb_gc_finalize_deferred() at the end of a collection,
> >>> > so I think you can apply the same patch.
> >>> >
> >>> > Evan
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> > On Tue, Jan 18, 2011 at 5:45 PM, WU Chehai <wuche...@gmail.com>
> wrote:
> >>> > > 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 pm, WU Chehai <wuche...@gmail.com> wrote:
> >>> > >> Hi, all
> >>> >
> >>> > >> The following code ends up an infinite loop
> >>> >
> >>> > >> require "tempfile"
> >>> > >> GC.stress = true
> >>> > >> t = Thread.new do
> >>> > >>   temp = Tempfile.new("tmp")
> >>> > >>   temp << "something"
> >>> > >>   temp = nil
> >>> > >>   h = 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)  from the global thread list and calls
> >>> > >> rb_thread_schedule in order to schedule another thread to run.
> >>> >
> >>> > >> - rb_thread_schedule invokes  rb_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?
> >>> >
> >>> > >> Thanks
> >>> >
> >>> > > --
> >>> > > You received this message because you are subscribed to the Google
> >>> > > Groups "Ruby Enterprise Edition" group.
> >>> > > To post to this group, send email to emm-ruby@googlegroups.com.
> >>> > > To unsubscribe from this group, send email to
> >>> > > emm-ruby+unsubscribe@googlegroups.com.
> >>> > > For more options, visit this group
> >>> > > athttp://groups.google.com/group/emm-ruby?hl=en.
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Ruby Enterprise Edition" group.
> >> To view this discussion on the web visit
> >> https://groups.google.com/d/msg/emm-ruby/-/bbyHMt0GSDkJ.
> >>
> >> To post to this group, send email to emm-ruby@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> emm-ruby+unsubscribe@googlegroups.com.
> >> For more options, visit this group at
> >> http://groups.google.com/group/emm-ruby?hl=en.
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Ruby Enterprise Edition" group.
> > To post to this group, send email to emm-ruby@googlegroups.com.
> > To unsubscribe from this group, send email to
> > emm-ruby+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/emm-ruby?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby Enterprise Edition" group.
> To post to this group, send email to emm-ruby@googlegroups.com.
> To unsubscribe from this group, send email to
> emm-ruby+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/emm-ruby?hl=en.
>
>

--0016368e2b4618886e04bd5b32b6
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Ahh, shoot. Thanks. Seems Google Groups had just appended a period to the h=
yperlink in the archives. Thanks and sorry for the email clutter.<div>N<br>=
<br><div class=3D"gmail_quote">On Tue, Apr 10, 2012 at 7:04 PM, Michael Chl=
etsos <span dir=3D"ltr">&lt;<a href=3D"mailto:mpchl...@gmail.com">mpchlets@=
gmail.com</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">take the period out of the link<br>
<br>
<a href=3D"https://github.com/twitter/rubyenterpriseedition187-248/commit/8=
3fc22" target=3D"_blank">https://github.com/twitter/rubyenterpriseedition18=
7-248/commit/83fc22</a><br>
<div class=3D"HOEnZb"><div class=3D"h5"><br>
On Tue, Apr 10, 2012 at 1:02 PM, Chehai WU &lt;<a href=3D"mailto:wuchehai@g=
mail.com">wuche...@gmail.com</a>&gt; wrote:<br>
&gt; The link works for me.<br>
&gt;<br>
&gt; On Tue, Apr 10, 2012 at 2:15 PM, Nate Westheimer &lt;<a href=3D"mailto=
:nate.westhei...@gmail.com">nate.westhei...@gmail.com</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hey All,<br>
&gt;&gt;<br>
&gt;&gt; That link to Twitter&#39;s GH is broken. Can anyone point me to a =
replacement<br>
&gt;&gt; for this?<br>
&gt;&gt;<br>
&gt;&gt; Thanks,<br>
&gt;&gt; Nate<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Thursday, August 25, 2011 1:25:03 AM UTC-4, WU Chehai wrote:<br=
>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Thanks very much! We are going to use your patch.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Jul 29, 11:03=A0am, Evan Weaver &lt;<a href=3D"mailto:ewea.=
....@gmail.com">ewea...@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; &gt; We ran into this bug in Kiji and fixed it the following<b=
r>
&gt;&gt;&gt; &gt; way:<a href=3D"https://github.com/twitter/rubyenterprisee=
dition187-248/commit/83fc22." target=3D"_blank">https://github.com/twitter/=
rubyenterpriseedition187-248/commit/83fc22.</a>..<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; It was causing a horrible fault for us where the readfds =
for the curr<br>
&gt;&gt;&gt; &gt; thread would get nulled out; thus you wait on nothing for=
 the full<br>
&gt;&gt;&gt; &gt; timeout (in Net::HTTP) in this case.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; REE also calls rb_gc_finalize_deferred() at the end of a =
collection,<br>
&gt;&gt;&gt; &gt; so I think you can apply the same patch.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; Evan<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; On Tue, Jan 18, 2011 at 5:45 PM, WU Chehai &lt;<a href=3D=
"mailto:wuche...@gmail.com">wuche...@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; &gt; &gt; Actually, regular Ruby 1.8.7-p330 does not has this =
issue.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt; The regular Ruby 1.8.7 finalizes objects every time =
a node is evaled<br>
&gt;&gt;&gt; &gt; &gt; if some conditions are met, so the temp file object =
(temp) is<br>
&gt;&gt;&gt; &gt; &gt; finalized before the thread exists. Everything shoul=
d be fine.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt; Therefore, this is a bug in current REE 1.8.7<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt; On Jan 17, 4:34=A0pm, WU Chehai &lt;<a href=3D"mailt=
o:wuche...@gmail.com">wuche...@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; &gt; &gt;&gt; Hi, all<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt;&gt; The following code ends up an infinite loop<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt;&gt; require &quot;tempfile&quot;<br>
&gt;&gt;&gt; &gt; &gt;&gt; GC.stress =3D true<br>
&gt;&gt;&gt; &gt; &gt;&gt; t =3D Thread.new do<br>
&gt;&gt;&gt; &gt; &gt;&gt; =A0 temp =3D Tempfile.new(&quot;tmp&quot;)<br>
&gt;&gt;&gt; &gt; &gt;&gt; =A0 temp &lt;&lt; &quot;something&quot;<br>
&gt;&gt;&gt; &gt; &gt;&gt; =A0 temp =3D nil<br>
&gt;&gt;&gt; &gt; &gt;&gt; =A0 h =3D Hash.new<br>
&gt;&gt;&gt; &gt; &gt;&gt; end<br>
&gt;&gt;&gt; &gt; &gt;&gt; t.join<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt;&gt; Our analysis shows that there is a race conditio=
n in REE 1.8.7:<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt;&gt; - When a thread finishes running, REE/Ruby deque=
ues it<br>
&gt;&gt;&gt; &gt; &gt;&gt; (rb_thread_remove) =A0from the global thread lis=
t and calls<br>
&gt;&gt;&gt; &gt; &gt;&gt; rb_thread_schedule in order to schedule another =
thread to run.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt;&gt; - rb_thread_schedule invokes =A0rb_gc_finalize_d=
eferred before<br>
&gt;&gt;&gt; &gt; &gt;&gt; scheduling another thread.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt;&gt; - rb_gc_finalize calls finalizer on Ruby Tempfil=
e object. The<br>
&gt;&gt;&gt; &gt; &gt;&gt; finalizer closes a file descriptor by calling rb=
_thread_fd_close<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt;&gt; - rb_thread_fd_close has a loop to iterate over =
all threads.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt;&gt; - However, the current thread is already dequeue=
d (it points to<br>
&gt;&gt;&gt; &gt; &gt;&gt; other<br>
&gt;&gt;&gt; &gt; &gt;&gt; threads, but no threads point back to it), so th=
e loop is actually<br>
&gt;&gt;&gt; &gt; &gt;&gt; an<br>
&gt;&gt;&gt; &gt; &gt;&gt; infinite loop.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt;&gt; We believe this issue also exists in regular Rub=
y 1.8.7, but we<br>
&gt;&gt;&gt; &gt; &gt;&gt; cannot<br>
&gt;&gt;&gt; &gt; &gt;&gt; reproduce it. Is this a bug in REE 1.8.7?<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt;&gt; Thanks<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; &gt; --<br>
&gt;&gt;&gt; &gt; &gt; You received this message because you are subscribed=
 to the Google<br>
&gt;&gt;&gt; &gt; &gt; Groups &quot;Ruby Enterprise Edition&quot; group.<br=
>
&gt;&gt;&gt; &gt; &gt; To post to this group, send email to <a href=3D"mail=
to:emm-ruby@googlegroups.com">emm-ruby@googlegroups.com</a>.<br>
&gt;&gt;&gt; &gt; &gt; To unsubscribe from this group, send email to<br>
&gt;&gt;&gt; &gt; &gt; <a href=3D"mailto:emm-ruby%2Bunsubscribe@googlegroup=
s.com">emm-ruby+unsubscribe@googlegroups.com</a>.<br>
&gt;&gt;&gt; &gt; &gt; For more options, visit this group<br>
&gt;&gt;&gt; &gt; &gt; athttp://<a href=3D"http://groups.google.com/group/e=
mm-ruby?hl=3Den" target=3D"_blank">groups.google.com/group/emm-ruby?hl=3Den=
</a>.<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; You received this message because you are subscribed to the Google=
 Groups<br>
&gt;&gt; &quot;Ruby Enterprise Edition&quot; group.<br>
&gt;&gt; To view this discussion on the web visit<br>
&gt;&gt; <a href=3D"https://groups.google.com/d/msg/emm-ruby/-/bbyHMt0GSDkJ=
" target=3D"_blank">https://groups.google.com/d/msg/emm-ruby/-/bbyHMt0GSDkJ=
</a>.<br>
&gt;&gt;<br>
&gt;&gt; To post to this group, send email to <a href=3D"mailto:emm-ruby@go=
oglegroups.com">emm-ruby@googlegroups.com</a>.<br>
&gt;&gt; To unsubscribe from this group, send email to<br>
&gt;&gt; <a href=3D"mailto:emm-ruby%2Bunsubscribe@googlegroups.com">emm-rub=
y+unsubscribe@googlegroups.com</a>.<br>
&gt;&gt; For more options, visit this group at<br>
&gt;&gt; <a href=3D"http://groups.google.com/group/emm-ruby?hl=3Den" target=
=3D"_blank">http://groups.google.com/group/emm-ruby?hl=3Den</a>.<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; You received this message because you are subscribed to the Google Gro=
ups<br>
&gt; &quot;Ruby Enterprise Edition&quot; group.<br>
&gt; To post to this group, send email to <a href=3D"mailto:emm-ruby@google=
groups.com">emm-ruby@googlegroups.com</a>.<br>
&gt; To unsubscribe from this group, send email to<br>
&gt; <a href=3D"mailto:emm-ruby%2Bunsubscribe@googlegroups.com">emm-ruby+un=
subscribe@googlegroups.com</a>.<br>
&gt; For more options, visit this group at<br>
&gt; <a href=3D"http://groups.google.com/group/emm-ruby?hl=3Den" target=3D"=
_blank">http://groups.google.com/group/emm-ruby?hl=3Den</a>.<br>
<br>
--<br>
You received this message because you are subscribed to the Google Groups &=
quot;Ruby Enterprise Edition&quot; group.<br>
To post to this group, send email to <a href=3D"mailto:emm-ruby@googlegroup=
s.com">emm-ruby@googlegroups.com</a>.<br>
To unsubscribe from this group, send email to <a href=3D"mailto:emm-ruby%2B=
unsubscribe@googlegroups.com">emm-ruby+unsubscribe@googlegroups.com</a>.<br=
>
For more options, visit this group at <a href=3D"http://groups.google.com/g=
roup/emm-ruby?hl=3Den" target=3D"_blank">http://groups.google.com/group/emm=
-ruby?hl=3Den</a>.<br>
<br>
</div></div></blockquote></div><br></div>

--0016368e2b4618886e04bd5b32b6--