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

Close the socket when there is an error using the socket #224

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

rbedia
Copy link
Contributor

@rbedia rbedia commented Oct 8, 2024

This fixes two related problems which made reconnecting not work after
the connection to the server gets dropped unexpectedly.

The MQTT client continues sending messages and on ESP32 eventually an
OSError is raised. The client must then reconnect. But reconnect was
failing because the Adafruit Connection Manager was returning the same
broken socket for the server since it hadn't yet been closed by
MiniMQTT.

Explicitly calling disconnect() would also not close the socket because
it tries to send the disconnect packet on the broken socket which raised
an OSError preventing the socket from being closed.

This fixes two related problems which made reconnecting not work after
the connection to the server gets dropped unexpectedly.

The MQTT client continues sending messages and on ESP32 eventually an
OSError is raised. The client must then reconnect. But reconnect was
failing because the Adafruit Connection Manager was returning the same
broken socket for the server since it hadn't yet been closed by
MiniMQTT.

Explicitly calling disconnect() would also not close the socket because
it tries to send the disconnect packet on the broken socket which raised
an OSError preventing the socket from being closed.
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Thank you!

@tannewt tannewt merged commit 62abc1a into adafruit:main Oct 9, 2024
1 check passed
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Oct 15, 2024
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.

2 participants