Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions internal/tiger/cmd/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"regexp"
"strings"
"testing"
"time"

"github.com/timescale/tiger-cli/internal/tiger/config"
)
Expand Down Expand Up @@ -410,10 +409,6 @@ func mockOpenBrowser(t *testing.T) func(string) error {

// Give the OAuth server a moment to start
go func() {
// Sleep to ensure the OAuth callback server is listening
// This prevents "EOF" errors in CI when the server hasn't started yet
time.Sleep(100 * time.Millisecond)
Comment on lines -413 to -415
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was just a confused attempt to fix the issue previously, but isn't actually needed. Because we open the net.Listener synchronously here, before we open the browser here, it should never be the case that the server isn't ready to handle incoming connections by the time this function executes.


// Make the OAuth callback request directly
callbackURL := fmt.Sprintf("%s?code=test-auth-code&state=%s", redirectURI, state)
t.Logf("Mock browser making callback request to: %s", callbackURL)
Expand Down
18 changes: 1 addition & 17 deletions internal/tiger/cmd/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (l *oauthLogin) getAccessToken(ctx context.Context) (string, error) {
return "", fmt.Errorf("failed to create local server: %w", err)
}
defer func() {
if err := server.Close(); err != nil {
if err := server.server.Shutdown(ctx); err != nil {
fmt.Fprintf(l.out, "Failed to close local server: %s\n", err)
}
}()
Expand Down Expand Up @@ -110,7 +110,6 @@ func (l *oauthLogin) generateRandomState(length int) (string, error) {
}

type oauthServer struct {
listener net.Listener
server *http.Server
oauthCfg oauth2.Config
resultChan <-chan oauthResult
Expand Down Expand Up @@ -162,26 +161,11 @@ func (l *oauthLogin) startOAuthServer(expectedState, codeVerifier string) (*oaut

return &oauthServer{
server: server,
listener: listener,
oauthCfg: oauthCfg,
resultChan: resultChan,
}, nil
}

func (s *oauthServer) Close() error {
cls := func(closer io.Closer) error {
if err := closer.Close(); err != nil && !errors.Is(err, net.ErrClosed) {
return err
}
return nil
}

return errors.Join(
cls(s.server),
cls(s.listener),
)
}
Comment on lines -171 to -183
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I decided to get rid of this function entirely and just call http.Server.Shutdown() directly above. The shutdown method already closes the listener internally, so we shouldn't need to do it ourselves, like it was previously being done here.


type oauthCallback struct {
oauthCfg oauth2.Config
expectedState string
Expand Down