Skip to content

Conversation

hakansa
Copy link
Member

@hakansa hakansa commented Sep 22, 2025

[client] Close Re-Auth Window If Client Is Already Connected

Describe your changes

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

@Copilot Copilot AI review requested due to automatic review settings September 22, 2025 12:52
Copy link

Copy link
Contributor

@Copilot Copilot AI left a 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 PR updates the re-authentication UI flow so that the login prompt automatically closes when the client is already connected.

  • showLoginURL now returns a CancelFunc and spins up a background goroutine to poll connection status.
  • The login window registers an OnClosed handler to cancel the goroutine.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

case <-ctx.Done():
return
case <-ticker.C:
status, err := conn.Status(s.ctx, &proto.StatusRequest{})
Copy link
Preview

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The 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
status, err := conn.Status(s.ctx, &proto.StatusRequest{})
status, err := conn.Status(ctx, &proto.StatusRequest{})

Copilot uses AI. Check for mistakes.

Comment on lines +1459 to +1461
conn, err := s.getSrvClient(failFastTimeout)
if err != nil {
return
Copy link
Preview

Copilot AI Sep 22, 2025

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.

Suggested change
conn, err := s.getSrvClient(failFastTimeout)
if err != nil {
return
var conn proto.ClientServiceClient
for {
select {
case <-ctx.Done():
return
default:
}
var err error
conn, err = s.getSrvClient(failFastTimeout)
if err != nil {
// Retry after a short delay if acquiring the client fails
time.Sleep(2 * time.Second)
continue
}
break

Copilot uses AI. Check for mistakes.

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.

1 participant