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 race condition in privkey generation #76

Merged
merged 3 commits into from
Feb 20, 2024

Conversation

lucabello
Copy link
Contributor

Issue

When trying to use this library in Alertmanager, I got the following error:

  File "/var/lib/juju/agents/unit-am-0/charm/lib/charms/observability_libs/v1/cert_handler.py", line 214, in _on_config_changed
    self._generate_csr(renew=True)
  File "/var/lib/juju/agents/unit-am-0/charm/lib/charms/observability_libs/v1/cert_handler.py", line 233, in _generate_csr
    raise RuntimeError(
RuntimeError: private key unset. call _generate_privkey() before you call this method.

In fact, _on_config_changed() doesn't call _generate_privkey().

The issue is that a race condition probably causes config-changed to arrive before certificates-relation-joined, which doesn't generate the private key beforehand.

Please note that calling the function multiple times isn't a problem as the function will just skip :)

Solution

Add a call to _generate_privkey() in the _on_config_changed() handler.

Copy link
Contributor

@PietroPasotti PietroPasotti left a comment

Choose a reason for hiding this comment

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

LGTM

@Abuelodelanada
Copy link
Contributor

Abuelodelanada commented Feb 20, 2024

This PR solves: #75 and #79

@Abuelodelanada Abuelodelanada merged commit b170b67 into main Feb 20, 2024
13 checks passed
@Abuelodelanada Abuelodelanada deleted the fix/cert-handler-privkey branch February 20, 2024 16:40
Abuelodelanada pushed a commit that referenced this pull request Feb 20, 2024
* fix race condition in privkey generation

* fix static checks in other libs

* tox fmt
Abuelodelanada added a commit that referenced this pull request Feb 20, 2024
* fix private key generation

* add missing _on_upgrade

* linting

* fix race condition in privkey generation (#76)

* fix race condition in privkey generation

* fix static checks in other libs

* tox fmt

* update LIBPATCH

---------

Co-authored-by: Luca Bello <36242061+lucabello@users.noreply.github.com>
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.

3 participants