Skip to contentSkip to conversation

asyncrpc: timeout attempting to create a TCP connection

PATCH In review Justin Bronder 2 participants 3 messages Nov 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 asyncrpc: timeout attempting to create a TCP connection

Timeout when trying to connect to an upstream that may be filtering connections (instead of waiting endlessly) and raise a ConnectionError which will allow the caller to note that the client is not connected. This, for instance, ensures that a firewalled BB_HASHSERVE_UPSTREAM will trigger warnings.

---
 lib/bb/asyncrpc/client.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/bb/asyncrpc/client.py +6 -1
index 9be49261c..92e140dfe 100644
@@ -68,7 +68,12 @@ class AsyncClient(object):
 
     async def connect_tcp(self, address, port):
         async def connect_sock():
-            reader, writer = await asyncio.open_connection(address, port)
+            try:
+                reader, writer = await asyncio.wait_for(
+                        asyncio.open_connection(address, port),
+                        timeout=5)
+            except asyncio.TimeoutError as e:
+                raise ConnectionError(f"Timeout connecting to {address}:{port}") from e
             return StreamConnection(reader, writer, self.timeout, self.max_chunk)
 
         self._connect_sock = connect_sock
Signature · 1 line
2.46.1
#1 lore raw
Quoted 17 lines · Justin Bronder via lists.openembedded.org

Timeout when trying to connect to an upstream that may be filtering connections (instead of waiting endlessly) and raise a ConnectionError which will allow the caller to note that the client is not connected. This, for instance, ensures that a firewalled BB_HASHSERVE_UPSTREAM will trigger warnings.

---
 lib/bb/asyncrpc/client.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/bb/asyncrpc/client.py +0 -0
index 9be49261c..92e140dfe 100644

lib/bb/asyncrpc/client.py class AsyncClient(object): · line 74

Quoted 8 lines
lib/bb/asyncrpc/client.py +4 -1
@@ -68,7 +68,12 @@ class AsyncClient(object):
 
     async def connect_tcp(self, address, port):
         async def connect_sock():
-            reader, writer = await asyncio.open_connection(address, port)
+            try:
+                reader, writer = await asyncio.wait_for(
+                        asyncio.open_connection(address, port),
+                        timeout=5)

Use self.timeout instead of "5" so that users can configure this through the normal timeout methods.

Quoted 17 lines
lib/bb/asyncrpc/client.py +2 -1
+            except asyncio.TimeoutError as e:
+                raise ConnectionError(f"Timeout connecting to {address}:{port}") from e
             return StreamConnection(reader, writer, self.timeout, self.max_chunk)
 
         self._connect_sock = connect_sock
--

2.46.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#16778): https://lists.openembedded.org/g/bitbake-devel/message/16778
Mute This Topic: https://lists.openembedded.org/mt/109407941/3616693
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw
Quoted 21 lines · Joshua Watt
Quoted 18 lines · Justin Bronder via lists.openembedded.org

Timeout when trying to connect to an upstream that may be filtering connections (instead of waiting endlessly) and raise a ConnectionError which will allow the caller to note that the client is not connected. This, for instance, ensures that a firewalled BB_HASHSERVE_UPSTREAM will trigger warnings.

---
 lib/bb/asyncrpc/client.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/bb/asyncrpc/client.py +0 -0
index 9be49261c..92e140dfe 100644
@@ -68,7 +68,12 @@ class AsyncClient(object):
 
Quoted 10 lines

lib/bb/asyncrpc/client.py class AsyncClient(object): · line 74

Quoted 7 lines
lib/bb/asyncrpc/client.py +4 -1
     async def connect_tcp(self, address, port):
         async def connect_sock():
-            reader, writer = await asyncio.open_connection(address, port)
+            try:
+                reader, writer = await asyncio.wait_for(
+                        asyncio.open_connection(address, port),
+                        timeout=5)

Use self.timeout instead of "5" so that users can configure this through the normal timeout methods.

I did that initially and you're correct to call me out on this. I should have added more context to my commit message. With a shorter timeout I get the warning 'BB_HASHSERVE_UPSTREAM is not valid, ...' from BBCooker catches the ConnectionError in handlePrServ. That's the behavior I believe is desirable.

When I use self.timeout (or longer timeouts in general), bitbake exits with:
Timeout while waiting for a reply from the bitbake server (60s at 17:27:09.872219)
and bitbake-cookerdaemon.log has BrokenPipeError being raised from python multiprocessing.

I started debugging this but then couldn't figure out how a user would actually configure the timeout. At least neither PRAsyncClient or the hashserv client look like they're setting it. So at that point I figured a static, shorter timeout for failing to connect would be reasonable.

If that argument doesn't pass muster, I'm happy to continue trying to figure out why using self.timeout isn't getting the warning from BBCooker but I suspect it's due to competing timeouts in separate modules.

Quoted 18 lines
Quoted 18 lines
lib/bb/asyncrpc/client.py +2 -1
+            except asyncio.TimeoutError as e:
+                raise ConnectionError(f"Timeout connecting to {address}:{port}") from e
             return StreamConnection(reader, writer, self.timeout, self.max_chunk)
 
         self._connect_sock = connect_sock
--

2.46.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#16778): https://lists.openembedded.org/g/bitbake-devel/message/16778
Mute This Topic: https://lists.openembedded.org/mt/109407941/3616693
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 1 line
Justin Bronder