[bitbake-devel] [PATCH] bitbake: prserv: fix ResourceWarning due to unclosed socket

Peter Kjellerstedt peter.kjellerstedt at axis.com
Tue Nov 12 22:19:00 UTC 2019


> -----Original Message-----
> From: bitbake-devel-bounces at lists.openembedded.org <bitbake-devel-
> bounces at lists.openembedded.org> On Behalf Of Mikko.Rapeli at bmw.de
> Sent: den 12 november 2019 08:29
> To: gavinli at thegavinli.com
> Cc: gavin at matician.com; bitbake-devel at lists.openembedded.org
> Subject: Re: [bitbake-devel] [PATCH] bitbake: prserv: fix ResourceWarning
> due to unclosed socket
> 
> Hi,
> 
> On Mon, Nov 11, 2019 at 02:17:39PM -0800, gavinli at thegavinli.com wrote:
> > From: Gavin Li <gavin at matician.com>
> >
> > With PRSERV_HOST = "localhost:0", this message would occasionally pop up
> > during the initial cache read:
> 
> Thanks for this fix!

Yes, finally! I've been hunting this for quite a while...

> It's not occasionally, it's all the time with zeus and Debian build
> container...

It is occasional for Warrior, so I guess it should be backported to 
both Zeus and Warrior.

> If it helps:
> Tested-by: Mikko Rapeli <mikko.rapeli at bmw.de>
> 
> -Mikko

//Peter

> > WARNING: /home/matic/ambayocto/poky/bitbake/lib/bb/cache.py:446:
> ResourceWarning: unclosed <socket.socket fd=10,
> family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0,
> laddr=('127.0.0.1', 45655)>
> >   value = pickled.load()
> >
> > The file location stated is irrelevant; it just happens to be wherever
> > CPython decides to run the garbage collector. The issue is that after we
> > fork off a PRServer, self.socket is also duplicated. The parent side of
> > it also needs to be closed.
> >
> > Signed-off-by: Gavin Li <gavin at matician.com>
> > ---
> >  bitbake/lib/prserv/serv.py | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/bitbake/lib/prserv/serv.py b/bitbake/lib/prserv/serv.py
> > index be3acec36a..1d9148b817 100644
> > --- a/bitbake/lib/prserv/serv.py
> > +++ b/bitbake/lib/prserv/serv.py
> > @@ -243,6 +243,7 @@ class PRServer(SimpleXMLRPCServer):
> >          try:
> >              pid = os.fork()
> >              if pid > 0:
> > +                self.socket.close() # avoid ResourceWarning in parent
> >                  return pid
> >          except OSError as e:
> >              raise Exception("%s [%d]" % (e.strerror, e.errno))
> > --
> > 2.23.0



More information about the bitbake-devel mailing list