Re: thread resource leaks if thread terminates with uncaught exception

Shiro Kawai <[email protected]> Tue, 17 Dec 2024 22:41:07 -1000
Newsgroups gmane.lisp.scheme.gauche
Message-ID <CALN0JNG-aot8JxV8QNUWTdqZfH9-KPsPW2gerRrAXsrC1sd0Lg@mail.gmail.com>
--===============8298839907645854883==
Content-Type: multipart/alternative; boundary="000000000000a728b206298760bc"

--000000000000a728b206298760bc
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Confirmed that if I comment out (when (=3D i 100) (error "i=3D100")) line, =
all
the terminated VMs are finalized in the next GC cycle, and that closes the
sockets.  If there's that error line, finalizers of VMs are never called.

Regarding avoiding thread-terminate! - it's a tough issue.  In general we
don't know whether a resource allocated in a VM should survive the VM or
not.  And we can't do much with the resources implicitly allocated in a
library function.  I feel robust GC is the only way in this case.


On Tue, Dec 17, 2024 at 10:06=E2=80=AFPM Jens Thiele <[email protected]> wrote=
:

> Shiro Kawai <[email protected]> writes:
>
> > Ok, I reproduced it.  The threads leave the socket to the localhost:808=
1
> > open  (You can see it with `lsof -p <pid>`), which consumes the fd pool=
.
> > `thread-terminate!` doesn't give the thread to cleanup, so relying on i=
t
> > should generally be avoided.
>
> The problem is how to avoid thread-terminate! in such cases. In this
> example it is the http-get which has no timeout. I also tried a version
> where the http-get is done in a child process and canceled with a
> sys-alarm - but this is really slow and sys-alarm only accepts full
> seconds as timeout. Maybe one could keep some worker processes around
> and use select but I think this gets complicated.
>
> Best regards
> Jens
>
>
> _______________________________________________
> Gauche-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/gauche-devel
>

--000000000000a728b206298760bc
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Confirmed that if I comment out (when (=3D i 100) (error &=
quot;i=3D100&quot;)) line, all the terminated VMs are finalized in the next=
 GC cycle, and that closes the sockets.=C2=A0 If there&#39;s that error lin=
e, finalizers of VMs are never=C2=A0called.=C2=A0=C2=A0<div><br></div><div>=
Regarding avoiding thread-terminate! - it&#39;s a tough issue.=C2=A0 In gen=
eral we don&#39;t know whether=C2=A0a resource=C2=A0allocated in a VM shoul=
d survive the VM or not.=C2=A0 And we can&#39;t do much with the resources=
=C2=A0implicitly allocated in a library function.=C2=A0 I feel robust GC is=
 the only way in this case.</div><div><br></div></div><br><div class=3D"gma=
il_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Tu=
e, Dec 17, 2024 at 10:06=E2=80=AFPM Jens Thiele &lt;<a href=3D"mailto:karme=
@karme.de">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmai=
l_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,20=
4,204);padding-left:1ex">Shiro Kawai &lt;<a href=3D"mailto:shiro.kawai@gmai=
l.com" target=3D"_blank">[email protected]</a>&gt; writes:<br>
<br>
&gt; Ok, I reproduced it.=C2=A0 The threads leave the socket to the localho=
st:8081<br>
&gt; open=C2=A0 (You can see it with `lsof -p &lt;pid&gt;`), which consumes=
 the fd pool.<br>
&gt; `thread-terminate!` doesn&#39;t give the thread to cleanup, so relying=
 on it<br>
&gt; should generally be avoided.<br>
<br>
The problem is how to avoid thread-terminate! in such cases. In this<br>
example it is the http-get which has no timeout. I also tried a version<br>
where the http-get is done in a child process and canceled with a<br>
sys-alarm - but this is really slow and sys-alarm only accepts full<br>
seconds as timeout. Maybe one could keep some worker processes around<br>
and use select but I think this gets complicated.<br>
<br>
Best regards<br>
Jens<br>
<br>
<br>
_______________________________________________<br>
Gauche-devel mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">Gau=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/gauche-devel" rel=
=3D"noreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listi=
nfo/gauche-devel</a><br>
</blockquote></div>

--000000000000a728b206298760bc--


--===============8298839907645854883==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============8298839907645854883==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Gauche-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gauche-devel

--===============8298839907645854883==--