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

handle partial socket send()'s #231

Merged
merged 3 commits into from
Jan 2, 2025
Merged

Conversation

dhalbert
Copy link
Contributor

@dhalbert dhalbert commented Jan 1, 2025

The library was using socket.send() directly, but not checking the return value to see if all the bytes were sent. So for larger packets, a partial send would go unnoticed. Added _send_bytes(), which calls send() until all bytes are sent, and also handles EAGAIN. I could have used socket.sendall(), but it doesn't handle EAGAIN.

I tested by sending 2900-byte packets to a no-history Adafruit IO test feed. @manchicken, who submitted #230, also tested.

@dhalbert dhalbert requested review from brentru and a team January 1, 2025 22:55
@manchicken
Copy link
Contributor

The patch you sent me seems to be working well. Thank you so much for your help, you saved my day!

@dhalbert dhalbert requested a review from tyeth January 2, 2025 13:56
Copy link
Member

@brentru brentru left a comment

Choose a reason for hiding this comment

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

Provided that sendall doesn't handle EAGAIN, I think the implementation you have for send_bytes is perfect for addressing this bug.

@dhalbert
Copy link
Contributor Author

dhalbert commented Jan 2, 2025

sendall() doesn't handle EAGAIN specially, surprisingly. It just raises it as an OSError.

@dhalbert dhalbert merged commit 75f3845 into adafruit:main Jan 2, 2025
1 check passed
@dhalbert dhalbert deleted the partial-send branch January 2, 2025 15:23
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 3, 2025
Updating https://github.com/adafruit/Adafruit_CircuitPython_MLX90393 to 2.3.1 from 2.3.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_MLX90393#45 from FoamyGuy/reset_sleep_ms

Updating https://github.com/adafruit/Adafruit_CircuitPython_MPRLS to 1.2.20 from 1.2.19:
  > Merge pull request adafruit/Adafruit_CircuitPython_MPRLS#20 from FoamyGuy/type_annotations

Updating https://github.com/adafruit/Adafruit_CircuitPython_PCF8575 to 1.0.7 from 1.0.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_PCF8575#8 from FoamyGuy/value_return_bool

Updating https://github.com/adafruit/Adafruit_CircuitPython_VL6180X to 1.4.15 from 1.4.14:
  > Merge pull request adafruit/Adafruit_CircuitPython_VL6180X#34 from FoamyGuy/min_delay_continuous

Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 7.11.0 from 7.10.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#232 from vladak/send_bytes_eagain
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#226 from vladak/connect_session_id
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#229 from manchicken/patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#231 from dhalbert/partial-send
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MiniMQTT sends malformed messages when messages are too large
3 participants