feat: Add message size validation to Bridge#59
feat: Add message size validation to Bridge#59beanrepo wants to merge 2 commits intoarduino:mainfrom
Conversation
|
|
||
|
|
||
| _reconnect_delay = 3.0 # seconds | ||
| _max_message_size = 256 # Maximum message size supported by Arduino router (bytes) |
There was a problem hiding this comment.
Could you add the link of the Arduino router code?
There was a problem hiding this comment.
Not sure if we need to add here.
Router should fail with proper error (payload too large) so ve can react properly.
We need to have this validation in a single place, imho
There was a problem hiding this comment.
@rjtokenring I agree with this approach to be more consistent and future-proof with Arduino Router and RPCLite. This needs to be addressed with an issue or PR on these repositories, because at the moment it is not possible to let users know when a message exceed this limit.
There was a problem hiding this comment.
It was just to understand where that value comes from...
Also a link in the PR description would be okay.
There was a problem hiding this comment.
@stefanotorneo referral links have been added to PR description. Anyway, this PR will be refactored to handle this error type according to previous discussion in this thread. We are waiting for an improvement in router bridge repository to handle a specific error code via RPC. Open issue here
| self._send_bytes(msgpack.packb(request)) | ||
| packed_data = msgpack.packb(request) | ||
| if len(packed_data) > _max_message_size: | ||
| with self.callbacks_lock: |
There was a problem hiding this comment.
Is this necessary? It is inside a try except, and in the except there are the same instructions.
Add message size validation to Bridge
The Arduino router bridge has a message size limitation of 256 bytes. When messages exceeding this limit are sent, the application crashes or blocks threads/processes instead of handling the error gracefully.
This PR adds validation logic to check message sizes before sending them through the bridge, with appropriate error handling for each message type.
Changes
_max_message_sizeconstant: Set to 256 bytes to match Arduino router limitsnotify()method:call()method:ValueErrorwith clear error message for oversized requests_send_response()method:Benefits
References