Open
Description
In the following is a code snippet from the Websocket class in async_substrate_interface (lines 531-545)
async def connect(self, force=False):
if self._exit_task:
self._exit_task.cancel()
if not self._initialized or force:
self._initialized = True
try:
self._receiving_task.cancel()
await self._receiving_task
await self.ws.close()
except (AttributeError, asyncio.CancelledError):
pass
self.ws = await asyncio.wait_for(
connect(self.ws_url, **self._options), timeout=10
)
self._receiving_task = asyncio.create_task(self._start_receiving())
There is an edge case error, where self._initialised is set to True, but then there is an error that occurs during the connection which is not caught here. So then self.ws is never set. This then leads to any future connections via the asyncsubstrateinterface class, thinking that the connection is initalized, whereas in reality self.ws = None. Causing an error that cannot fix itself.
Fix: Move self._initialized = True to after self.ws = .... so it is only set after a successful connection is made