Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions botoy/_internal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ async def wait(self):
break
await self.ws.wait_closed()
await asyncio.sleep(1)
if not self.reconnect_task:
break
await self.reconnect_task
if self.state != "connected":
if self.reconnect_task:
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reconnect_task attribute is not initialized in the __init__ method. This means if the wait() method is called before any connection attempt that would set reconnect_task in _read_loop, line 228 will raise an AttributeError when checking if self.reconnect_task:. The attribute should be initialized to None in the constructor.

Copilot uses AI. Check for mistakes.
try:
await self.reconnect_task
except Exception:
pass
Comment on lines +231 to +232
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bare except Exception: clause silently swallows all exceptions from the reconnect task. This makes debugging difficult and could hide important errors. Consider logging the exception before suppressing it, or at minimum catching more specific exceptions that are expected during reconnection attempts.

Suggested change
except Exception:
pass
except Exception as e:
logger.exception("Exception occurred while awaiting reconnect_task")

Copilot uses AI. Check for mistakes.
if self.state != "connected" and not self.reconnect_task:
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exit condition logic has changed in a way that could cause premature exit. The original logic would break if reconnect_task was falsy OR if the state wasn't "connected". The new logic only breaks if BOTH conditions are true (state is not "connected" AND no reconnect_task). This means if the state is "disconnected" or "disconnecting" but somehow reconnect_task is truthy, the loop will continue indefinitely. Consider whether this behavior is intentional for the fix.

Suggested change
if self.state != "connected" and not self.reconnect_task:
if self.state != "connected" or not self.reconnect_task:

Copilot uses AI. Check for mistakes.
break

def run(self, reload=False):
Expand Down