Skip to content
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 browser opens in rill start when the port is taken #6328

Merged
merged 1 commit into from
Dec 23, 2024
Merged
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
16 changes: 13 additions & 3 deletions cli/pkg/local/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ func (a *App) PollServer(ctx context.Context, httpPort int, openOnHealthy, secur
uri := fmt.Sprintf("%s://localhost:%d", scheme, httpPort)

for {
// Wait a bit before (re)trying.
//
// We sleep before the first health check as a slightly hacky way to protect against the situation where
// another Rill server is already running, which will pass the health check as a false positive.
// By sleeping first, the ctx is in practice sure to have been cancelled with a "port taken" error at that point.
time.Sleep(250 * time.Millisecond)

// Check for cancellation
if ctx.Err() != nil {
return
Expand All @@ -427,14 +434,17 @@ func (a *App) PollServer(ctx context.Context, httpPort int, openOnHealthy, secur
break
}
}

// Wait a bit and retry
time.Sleep(250 * time.Millisecond)
}

// Health check succeeded
a.Logger.Infof("Serving Rill on: %s", uri)
if openOnHealthy {
// Check for cancellation again to be safe
if ctx.Err() != nil {
return
}

// Open the browser
err := browser.Open(uri)
if err != nil {
a.Logger.Debugf("could not open browser: %v", err)
Expand Down
Loading