-
-
Notifications
You must be signed in to change notification settings - Fork 906
[client] Close Re-Auth Window If Client Is Already Connected #4525
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1354,7 +1354,13 @@ func (s *serviceClient) updateConfig() error { | |||||
} | ||||||
|
||||||
// showLoginURL creates a borderless window styled like a pop-up in the top-right corner using s.wLoginURL. | ||||||
func (s *serviceClient) showLoginURL() { | ||||||
// It also starts a background goroutine that periodically checks if the client is already connected | ||||||
// and closes the window if so. The goroutine can be cancelled by the returned CancelFunc, and it is | ||||||
// also cancelled when the window is closed. | ||||||
func (s *serviceClient) showLoginURL() context.CancelFunc { | ||||||
|
||||||
// create a cancellable context for the background check goroutine | ||||||
ctx, cancel := context.WithCancel(s.ctx) | ||||||
|
||||||
resIcon := fyne.NewStaticResource("netbird.png", iconAbout) | ||||||
|
||||||
|
@@ -1363,6 +1369,8 @@ func (s *serviceClient) showLoginURL() { | |||||
s.wLoginURL.Resize(fyne.NewSize(400, 200)) | ||||||
s.wLoginURL.SetIcon(resIcon) | ||||||
} | ||||||
// ensure goroutine is cancelled when the window is closed | ||||||
s.wLoginURL.SetOnClosed(func() { cancel() }) | ||||||
// add a description label | ||||||
label := widget.NewLabel("Your NetBird session has expired.\nPlease re-authenticate to continue using NetBird.") | ||||||
|
||||||
|
@@ -1443,7 +1451,39 @@ func (s *serviceClient) showLoginURL() { | |||||
) | ||||||
s.wLoginURL.SetContent(container.NewCenter(content)) | ||||||
|
||||||
// start a goroutine to check connection status and close the window if connected | ||||||
go func() { | ||||||
ticker := time.NewTicker(5 * time.Second) | ||||||
defer ticker.Stop() | ||||||
|
||||||
conn, err := s.getSrvClient(failFastTimeout) | ||||||
if err != nil { | ||||||
return | ||||||
} | ||||||
|
||||||
for { | ||||||
select { | ||||||
case <-ctx.Done(): | ||||||
return | ||||||
case <-ticker.C: | ||||||
status, err := conn.Status(s.ctx, &proto.StatusRequest{}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Status RPC uses s.ctx instead of the cancellable ctx created for this goroutine, meaning in-flight calls won’t be canceled when cancel() is invoked or when the window closes. Use ctx so the RPC respects cancellation.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
if err != nil { | ||||||
continue | ||||||
} | ||||||
if status.Status == string(internal.StatusConnected) { | ||||||
if s.wLoginURL != nil { | ||||||
s.wLoginURL.Close() | ||||||
} | ||||||
return | ||||||
} | ||||||
} | ||||||
} | ||||||
}() | ||||||
|
||||||
s.wLoginURL.Show() | ||||||
|
||||||
// return cancel func so callers can stop the background goroutine if desired | ||||||
return cancel | ||||||
} | ||||||
|
||||||
func openURL(url string) error { | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If acquiring the service client fails once, the goroutine exits and the auto-close behavior never runs. This makes the feature inert under transient startup/network conditions. Consider retrying acquisition inside the loop (or continuing until ctx.Done()) so it recovers from transient failures.
Copilot uses AI. Check for mistakes.