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

docs: tweak the wording around can_connect() usage #1123

Merged
merged 4 commits into from Feb 14, 2024

Conversation

tonyandrewmeyer
Copy link
Contributor

@tonyandrewmeyer tonyandrewmeyer commented Feb 7, 2024

can_connect() is a point-in-time check, and, if used as a guard for interacting with Pebble, introduces a race condition where Pebble was responding at the can_connect() time, but is not when the rest of the work is done.

We already encourage people to handle errors communicating with Pebble when doing the later work (catching ConnectionError), which means that most of the time the can_connect call is not providing any value (and incurs a small cost). However, the documentation, particularly the example, encourages this pattern, and this has been copied to many other places (charm sources, docs).

This PR adjusts the documentation to be less encouraging of can_connect() use as a guard, and changes the example to one where a point-in-time check is wanted (for collecting unit status).

@tonyandrewmeyer tonyandrewmeyer mentioned this pull request Feb 7, 2024
11 tasks
@tonyandrewmeyer tonyandrewmeyer marked this pull request as ready for review February 14, 2024 06:58
@benhoyt benhoyt merged commit 9a72677 into canonical:main Feb 14, 2024
28 checks passed
@tonyandrewmeyer tonyandrewmeyer deleted the adjust-can-connect-wording branch February 15, 2024 03:03
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.

None yet

2 participants