From c236f1671730e7650722035db81e5537ab74e58b Mon Sep 17 00:00:00 2001 From: Tim Sheerman-Chase Date: Mon, 20 Apr 2026 15:57:36 +0100 Subject: [PATCH] Fix unbound stream variable in DHT provider_store.py --- libp2p/kad_dht/provider_store.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libp2p/kad_dht/provider_store.py b/libp2p/kad_dht/provider_store.py index 3da4ff9a5..5d9973c7b 100644 --- a/libp2p/kad_dht/provider_store.py +++ b/libp2p/kad_dht/provider_store.py @@ -226,6 +226,8 @@ async def _send_add_provider(self, peer_id: ID, key: bytes) -> bool: True if the message was successfully sent and acknowledged """ + stream = None + try: result = False # Open a stream to the peer @@ -298,7 +300,8 @@ async def _send_add_provider(self, peer_id: ID, key: bytes) -> bool: logger.warning(f"Error sending ADD_PROVIDER to {peer_id}: {e}") finally: - await stream.close() + if stream is not None: + await stream.close() return result async def find_providers(self, key: bytes, count: int = 20) -> list[PeerInfo]: