Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve detection of disconnected websocket between services #11069

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion chia/daemon/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def _get(self, request: WsRpcMessage) -> WsRpcMessage:
request_id = request["request_id"]
self._request_dict[request_id] = asyncio.Event()
string = dict_to_json_str(request)
if self.websocket is None:
if self.websocket is None or self.websocket.closed:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that I've only tested this path, in client.py

raise Exception("Websocket is not connected")
asyncio.create_task(self.websocket.send_str(string))

Expand Down
6 changes: 3 additions & 3 deletions chia/rpc/rpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def stop(self):
await self.client_session.close()

async def _state_changed(self, *args):
if self.websocket is None:
if self.websocket is None or self.websocket.closed:
return None
payloads: List[Dict] = await self.rpc_api._state_changed(*args)

Expand All @@ -70,7 +70,7 @@ async def _state_changed(self, *args):
for payload in payloads:
if "success" not in payload["data"]:
payload["data"]["success"] = True
if self.websocket is None:
if self.websocket is None or self.websocket.closed:
return None
try:
await self.websocket.send_str(dict_to_json_str(payload))
Expand All @@ -79,7 +79,7 @@ async def _state_changed(self, *args):
self.log.warning(f"Sending data failed. Exception {tb}.")

def state_changed(self, *args):
if self.websocket is None:
if self.websocket is None or self.websocket.closed:
return None
asyncio.create_task(self._state_changed(*args))

Expand Down