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

fix: tedge mqtt ignoring ctrl-c when connection fails #2950

Merged

Conversation

didier-wenzek
Copy link
Contributor

Proposed changes

As rumqttc doesn't trigger a client disconnect when the connection is not established,
one has to combine a client disconnect with the use of an AtomicBool to break the event loop
if for some reason the connection is not established when the user hits ctrl-c.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

#2949

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 44.44444% with 5 lines in your changes missing coverage. Please review.

Project coverage is 78.2%. Comparing base (5826ae2) to head (ed0b7fd).
Report is 10 commits behind head on main.

Additional details and impacted files
Files Coverage Δ
crates/core/tedge/src/cli/mqtt/mod.rs 66.6% <80.0%> (-2.6%) ⬇️
crates/core/tedge/src/cli/mqtt/subscribe.rs 0.0% <0.0%> (ø)

... and 11 files with indirect coverage changes

Copy link
Contributor

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
453 0 3 453 100 1h1m13.030747999s

Err(err) => {
if interrupted.load(Ordering::Relaxed) {
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

I was initially wondering why the same is not done for publish as well, but then noticed that the publisher already breaks out of the loop on any connection error. I'm assuming that the behaviour is different here (not breaking out of the loop on any connection error) to handle reconnection cases as well, esp for long running subscribers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the point is to handle long running subscribers ignoring connection blips unless the user requests to break.

Err(err) => {
if interrupted.load(Ordering::Relaxed) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the performance of these utilities is not at all a concern, but immediate response to the Ctrl + C command is desired, isn't it better to go with a stronger ordering guarantee using Ordering::Acquire and Ordering::Release so that the program closes as soon as Ctrl + C is pressed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. A user will not notice the difference. Besides, the main delay is introduced by the event loop. The break will occur only after a connection error is reported.

Copy link
Contributor

Choose a reason for hiding this comment

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

The delay (of up to 1 second) between pressing ctrl+c is on there when the MQTT broker is not reachable, so I don't think the user will run into it very often, so it's ok from UX perspective.

Copy link
Contributor

@reubenmiller reubenmiller left a comment

Choose a reason for hiding this comment

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

Approved

@reubenmiller reubenmiller added theme:mqtt Theme: mqtt and mosquitto related topics theme:cli Theme: cli related topics labels Jun 19, 2024
@didier-wenzek didier-wenzek added this pull request to the merge queue Jun 19, 2024
Merged via the queue into thin-edge:main with commit 87e84d5 Jun 19, 2024
33 checks passed
@didier-wenzek didier-wenzek deleted the fix/tedge-mqtt-ignores-ctrl-c branch June 19, 2024 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:cli Theme: cli related topics theme:mqtt Theme: mqtt and mosquitto related topics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants