[bitbake-devel,1.44,4/9] prserv: fix ResourceWarning due to unclosed socket

Submitted by Armin Kuster on Nov. 23, 2019, 4:24 p.m. | Patch ID: 167344


Message ID 1574526299-21018-4-git-send-email-akuster808@gmail.com
State New
Headers show

Commit Message

Armin Kuster Nov. 23, 2019, 4:24 p.m.
From: Gavin Li <gavin@matician.com>

With PRSERV_HOST = "localhost:0", this message would occasionally pop up
during the initial cache read:

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=('', 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@matician.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
 lib/prserv/serv.py | 1 +
 1 file changed, 1 insertion(+)

Patch hide | download patch | download mbox

diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index be3acec..1d9148b 100644
--- a/lib/prserv/serv.py
+++ b/lib/prserv/serv.py
@@ -243,6 +243,7 @@  class PRServer(SimpleXMLRPCServer):
             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))