Skip to content

Commit

Permalink
Fixes bug in MQTT RPCServer
Browse files Browse the repository at this point in the history
  • Loading branch information
klpanagi committed Dec 19, 2024
1 parent 61ea05a commit 524d391
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions commlib/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def __del__(self):
try:
self.stop()
except:
# Silence
pass


Expand Down
17 changes: 17 additions & 0 deletions commlib/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ def __init__(
self._t_stop_event = None
self._comm_obj = CommRPCMessage()

def _validate_rpc_req_msg(self, msg: CommRPCMessage) -> bool:
"""_validate_rpc_req_msg.
Validates the RPC request message by checking if the message header is present and the reply_to field is not empty or None.
Args:
msg (CommRPCMessage): The RPC request message to validate.
Returns:
bool: True if the RPC request message is valid, False otherwise.
"""

if msg.header is None:
return False
elif msg.header.reply_to in ("", None):
return False
return True

def run_forever(self):
"""run_forever.
Run the RPC service in background and blocks the main thread.
Expand Down
4 changes: 2 additions & 2 deletions commlib/transports/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def _on_request_internal(self, client: Any, userdata: Any, msg: Dict[str, Any]):
else:
resp = clb(msg_type.Request(**req_msg.data))
resp = resp.dict()
self._send_response(resp, req.header.reply_to)
self._send_response(resp, req_msg.header.reply_to)
except Exception as exc:
self.log.error(str(exc), exc_info=False)
return
Expand Down Expand Up @@ -793,7 +793,7 @@ def call(self, msg: RPCMessage.Request, timeout: float = 30) -> RPCMessage.Respo
else:
if not isinstance(msg, self._msg_type.Request):
raise ValueError("Message type not valid")
data = msg.dict()
data = msg.model_dump()

self._response = None

Expand Down

0 comments on commit 524d391

Please sign in to comment.