-
Notifications
You must be signed in to change notification settings - Fork 0
Fix double fetch #274
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 double fetch #274
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes a bug where user creation could be triggered multiple times by centralizing the user creation logic into the NewRadiance function during application initialization. Additionally, it simplifies the UserInfo.GetData() interface by removing the unnecessary error return value and performs minor cleanup of logging statements.
- Moves user creation to
NewRadianceto prevent double-fetching during configuration or API operations - Simplifies
UserInfo.GetData()interface by removing error return, making it more straightforward to use - Removes verbose trace/debug logging and cleans up error handling across multiple modules
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| radiance.go | Adds centralized user creation via maybeCreateNewUser() called during initialization, removes APIHandler from config options |
| config/fetcher.go | Removes ensureUser() method and APIClient dependency, eliminating potential double-fetch |
| config/fetcher_test.go | Updates test instantiation to remove APIClient parameter from newFetcher() |
| config/config.go | Removes APIHandler from Options struct and simplifies shouldRefetch() logic, removes debug logging |
| config/config_test.go | Updates test to remove APIClient parameter from newFetcher() |
| common/user.go | Updates GetData() interface signature to remove error return |
| common/user/user.go | Implements simplified GetData() without error return, adds logging for user data changes |
| api/api.go | Updates NewAPIClient to use simplified GetData() without error handling |
| api/user_test.go | Updates mock to match new GetData() signature |
| issue/issue.go | Refactors to use AccountType() method instead of manual user data checks |
| telemetry/otel.go | Updates to use simplified GetData() with nil check instead of error handling |
| servers/manager.go | Removes verbose trace logging for server operations |
| vpn/boxoptions.go | Removes trace logging for config file unmarshalling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
So I think the only issue with this is for the case where users have poor/partially blocked connectivity, with a mobile user in Iran as maybe the quintessential example. In that scenario, the single call to create a user might fail. If it does, they're dead in the water because we'll never try again. In that sequence, I think it makes sense to:
|
|
@myleshorton I re-added the ensure user check when fetching config and updated the fetch loop to retry on failure with exponential backoff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Sorry got caught up in the infrastructure issues today but will look again soon. |
config/fetcher.go
Outdated
| } else { | ||
| slog.Info("Created new user") | ||
| } | ||
| if f.apiClient == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would opt for failing fast here and creating an error if apiClient is nil in newFetcher
radiance.go
Outdated
|
|
||
| userInfo := user.NewUserConfig(platformDeviceID, dataDir, opts.Locale) | ||
| apiHandler := api.NewAPIClient(httpClientWithTimeout, userInfo, dataDir) | ||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only issue here is that this becomes the one call that could take a long time in NewRadiance. If MaybeCreateNewUser takes a long time, which it could due to the time it can take the various kindling methods to start up, what happens?
|
Added a couple of comments, but, stepping back for a second, the user listener change I believe was added to account for two cases:
I think you could handle both of those with a small modification to the prior code, particularly in In other words, I think we want to listen for a user's status changing, not a user being created. |
4485889 to
505b711
Compare
|
Yeah, you're right. The changes should be kept to a minimum. All fixed. |
myleshorton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!
This pull request makes targeted improvements to the configuration handling logic, focusing on more precise detection of when a configuration refetch is necessary and enhancing debug logging for user changes. The main changes are in the
config/config.gofile.Improvements to config refetch logic and logging:
shouldRefetchfunction to only trigger config refetches when both the new and old user info are non-nil and the old user has a valid legacy ID, reducing unnecessary refetches.Logging cleanup:
fetchConfigmethod to avoid excessive logging.closes getlantern/engineering/issues/2899