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