Skip to content

Conversation

lidel
Copy link
Member

@lidel lidel commented Aug 13, 2025

@lidel lidel requested review from hsanjuan and gammazero August 13, 2025 10:02
Copy link

codecov bot commented Aug 13, 2025

Codecov Report

❌ Patch coverage is 29.79110% with 773 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.46%. Comparing base (54b62d4) to head (ed4093d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
autoconf/fetch.go 54.56% 138 Missing and 41 partials ⚠️
autoconf/expansion.go 0.00% 119 Missing ⚠️
autoconf/updater.go 0.00% 113 Missing ⚠️
autoconf/delegated_routing.go 0.00% 90 Missing ⚠️
autoconf/endpoints.go 0.00% 76 Missing ⚠️
autoconf/client.go 58.97% 55 Missing and 9 partials ⚠️
autoconf/lifecycle.go 0.00% 55 Missing ⚠️
autoconf/fallbacks.go 0.00% 52 Missing ⚠️
autoconf/types.go 44.11% 19 Missing ⚠️
bootstrap/bootstrap.go 50.00% 6 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #997      +/-   ##
==========================================
- Coverage   61.56%   60.46%   -1.10%     
==========================================
  Files         257      266       +9     
  Lines       32161    33257    +1096     
==========================================
+ Hits        19799    20109     +310     
- Misses      10751    11483     +732     
- Partials     1611     1665      +54     
Files with missing lines Coverage Δ
bootstrap/bootstrap.go 33.98% <50.00%> (-0.16%) ⬇️
autoconf/types.go 44.11% <44.11%> (ø)
autoconf/fallbacks.go 0.00% <0.00%> (ø)
autoconf/lifecycle.go 0.00% <0.00%> (ø)
autoconf/client.go 58.97% <58.97%> (ø)
autoconf/endpoints.go 0.00% <0.00%> (ø)
autoconf/delegated_routing.go 0.00% <0.00%> (ø)
autoconf/updater.go 0.00% <0.00%> (ø)
autoconf/expansion.go 0.00% <0.00%> (ø)
autoconf/fetch.go 54.56% <54.56%> (ø)

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

lidel added a commit to ipfs/rainbow that referenced this pull request Aug 13, 2025
lidel added a commit to ipfs/kubo that referenced this pull request Aug 13, 2025
@lidel lidel marked this pull request as ready for review August 13, 2025 10:47
@lidel lidel requested a review from a team as a code owner August 13, 2025 10:47
Comment on lines +197 to +205
func WithRefreshInterval(interval time.Duration) Option {
return func(c *Client) error {
if interval <= 0 {
return fmt.Errorf("refresh interval must be positive")
}
c.refreshInterval = interval
return nil
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to introduce a minimum refresh interval that is hardcoded. We don't want people setting their refresh interval to 1s by mistake.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is tricky because we have tests that depend on very low interval to confirm things work.

What is more idiomatic, use testing.Testing() to detect test mode and lift min interval limit, or have explicit WithTestMode()?

Copy link
Contributor

@hsanjuan hsanjuan 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 for writing such good code!

Comment on lines +53 to +65
// Stop gracefully stops the background updater if it's running.
// This is an alternative to cancelling the context passed to Start().
// It's safe to call Stop() multiple times.
func (c *Client) Stop() {
c.updaterMu.Lock()
defer c.updaterMu.Unlock()

if c.updater != nil {
c.updater.Stop()
c.updater = nil
log.Infof("Stopped autoconf background updater")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we can control lifecycle via context, perhaps we can avoid having a second way?

Copy link
Contributor

@gammazero gammazero Aug 14, 2025

Choose a reason for hiding this comment

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

I prefer to avoid lifecycle contexts if at all possible, and if they are the best solution, then do not make the visible outside the package and the context is not kept in the type. In other words, only keep the cancel function as a data member in the type and pass the context into a goroutine started when the type instance is created.

gammazero and others added 5 commits August 14, 2025 10:41
requests are made infrequently (24h default), no benefit from connection pooling
- make BackgroundUpdater type private (backgroundUpdater)
- move updater callbacks to Client options (WithOnNewVersion, WithOnRefresh, WithOnRefreshError)
- fix race conditions with proper mutex protection
- handle zero timeout edge case in Start()
- simplify API by hiding updater as implementation detail
avoids unnecessary config resolution calls when node is well-connected
@lidel lidel merged commit fe649ee into main Aug 15, 2025
16 checks passed
@lidel lidel deleted the feat-mainnet-autoconfig branch August 15, 2025 02:58
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