summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-09-02 21:50:22 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-10-11 21:57:28 +0100
commit67e4012e6261b3e8c7e980dd546acc65c038341d (patch)
treecb5205fb933c684a6fcea015fc099c6a326979f5 /bitbake
parent189a6d452e3037c9e94ccdf6af38359fc6058064 (diff)
downloadpoky-67e4012e6261b3e8c7e980dd546acc65c038341d.tar.gz
bitbake: asyncrpc/client: Fix unix domain socket chdir race issues
The connect_unix() call had a bug where if a relative path to a socket was passed (which the non-async client always does), and the current working directory was changed after the initial call, it would fail to reconnect if it became disconnected, since the socket couldn't be found relative to the new current working directory. To work around this, change the socket connection for UNIX domain sockets to be synchronous and change current working before connecting. This isn't ideal since the connection could block the entire event loop, but in practice this shouldn't happen since the socket are local files anyway. Help debugging and resolving from Joshua Watt. (Bitbake rev: 6603c3e39f1cf746669ec6c9f0be8c6e6ece426e) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 5964bb67bb20df7f411ee0650cf189504a05cf25) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/asyncrpc/client.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/bitbake/lib/bb/asyncrpc/client.py b/bitbake/lib/bb/asyncrpc/client.py
index 881434d2e9..fa042bbe87 100644
--- a/bitbake/lib/bb/asyncrpc/client.py
+++ b/bitbake/lib/bb/asyncrpc/client.py
@@ -31,7 +31,17 @@ class AsyncClient(object):
31 31
32 async def connect_unix(self, path): 32 async def connect_unix(self, path):
33 async def connect_sock(): 33 async def connect_sock():
34 return await asyncio.open_unix_connection(path) 34 # AF_UNIX has path length issues so chdir here to workaround
35 cwd = os.getcwd()
36 try:
37 os.chdir(os.path.dirname(path))
38 # The socket must be opened synchronously so that CWD doesn't get
39 # changed out from underneath us so we pass as a sock into asyncio
40 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0)
41 sock.connect(os.path.basename(path))
42 finally:
43 os.chdir(cwd)
44 return await asyncio.open_unix_connection(sock=sock)
35 45
36 self._connect_sock = connect_sock 46 self._connect_sock = connect_sock
37 47
@@ -150,14 +160,8 @@ class Client(object):
150 setattr(self, m, self._get_downcall_wrapper(downcall)) 160 setattr(self, m, self._get_downcall_wrapper(downcall))
151 161
152 def connect_unix(self, path): 162 def connect_unix(self, path):
153 # AF_UNIX has path length issues so chdir here to workaround 163 self.loop.run_until_complete(self.client.connect_unix(path))
154 cwd = os.getcwd() 164 self.loop.run_until_complete(self.client.connect())
155 try:
156 os.chdir(os.path.dirname(path))
157 self.loop.run_until_complete(self.client.connect_unix(os.path.basename(path)))
158 self.loop.run_until_complete(self.client.connect())
159 finally:
160 os.chdir(cwd)
161 165
162 @property 166 @property
163 def max_chunk(self): 167 def max_chunk(self):