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(client): race in cert renewal #42

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

lidel
Copy link
Contributor

@lidel lidel commented Jan 17, 2025

Fixes #28.

Previously, we had global defaultCertCache and relied on GetConfigForCert recursively calling newCertmagicConfig, which was likely a surface for racy bug from #28 where p2p-forge instance was not fully wired up yet

Using custom things with certmagic is pretty awkward due to circular dependency that shows only when custom config, cache, storage are issues are used.

In this PR, the circular dependency is solved in alternative way:

  1. replaced newCertmagicConfig with simpler configGetter that operates on final certmagic inside of manager – this removes recursion and racy surface for certmagic.*Default* logic which is used if any of required fields is not set yet
  2. config returned by P2PForgeCertMgr.TLSConfig() now explicitly uses P2PForgeCertMgr.certmagic.GetCertificate to remove surface of any indirection

Together, surface for racy behavior should be removed, allowing user to have default certmagic doing some unrelated things, and then one or more lip2p with multiple instances of p2p-forge/client in their app, without interfering with each other.

TODO

lidel added 2 commits January 17, 2025 23:43
this refactor ensures unique cache per instance is initialized,
and the global default cert management in certmagic is not triggered.

circular dependency is solved in alrernative way:
1. recursive call for newCertmagicConfig is removed and replaced by simpler configGetter
2. TLSConfig() ensures correct GetCertificate() is used
@lidel lidel requested a review from aschmahmann January 17, 2025 23:38
@lidel lidel changed the title fix: race in cert renewal fix(client): race in cert renewal Jan 17, 2025
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.

client: cert renewal errors in a loop until restart
1 participant