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-09-05 12:54:25 +0100
commite490bc826287b681a62868267bf238843bf5b3c1 (patch)
treef5fdb7b4e2ee7dc2d2405da1514ee069ca51accb /bitbake
parent58c42911d452e57505b08915618723961df5ef89 (diff)
downloadpoky-e490bc826287b681a62868267bf238843bf5b3c1.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: 5964bb67bb20df7f411ee0650cf189504a05cf25) 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):