Skip to content

Commit

Permalink
Mac/Windows: Check if daemon able to serve after it starts
Browse files Browse the repository at this point in the history
This PR add time limit (15 sec) to make sure daemon able to serve
the requests after it is start because sometimes just after start
it takes time to serve.

fixes: #3148
  • Loading branch information
praveenkumar authored and anjannath committed May 4, 2022
1 parent 22a3339 commit 21adefa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
10 changes: 1 addition & 9 deletions pkg/crc/preflight/preflight_checks_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/code-ready/crc/pkg/crc/cache"
"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/daemonclient"
"github.com/code-ready/crc/pkg/crc/logging"
"github.com/code-ready/crc/pkg/crc/version"
crcos "github.com/code-ready/crc/pkg/os"
Expand Down Expand Up @@ -191,13 +190,6 @@ func checkIfDaemonPlistFileExists() error {
return nil
}

func daemonRunning() bool {
if _, err := daemonclient.GetVersionFromDaemonAPI(); err != nil {
return false
}
return true
}

func fixDaemonPlistFileExists() error {
if err := olderDaemonVersionRunning(); err != nil {
if err := killDaemonProcess(); err != nil {
Expand Down Expand Up @@ -232,5 +224,5 @@ func fixPlistFileExists(agentConfig launchd.AgentConfig) error {
logging.Debugf("failed to restart launchd agent '%s': %v", agentConfig.Label, err.Error())
return err
}
return nil
return waitForDaemonRunning()
}
20 changes: 20 additions & 0 deletions pkg/crc/preflight/preflight_checks_nonlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
package preflight

import (
"context"
"fmt"
"runtime"
"strings"
"time"

"github.com/code-ready/crc/pkg/crc/daemonclient"
crcerrors "github.com/code-ready/crc/pkg/crc/errors"
"github.com/code-ready/crc/pkg/crc/logging"
"github.com/shirou/gopsutil/v3/process"
)
Expand Down Expand Up @@ -70,3 +74,19 @@ func olderDaemonVersionRunning() error {
}
return daemonclient.CheckIfOlderVersion(v)
}

func daemonRunning() bool {
if _, err := daemonclient.GetVersionFromDaemonAPI(); err != nil {
return false
}
return true
}

func waitForDaemonRunning() error {
return crcerrors.Retry(context.Background(), 15*time.Second, func() error {
if !daemonRunning() {
return &crcerrors.RetriableError{Err: fmt.Errorf("daemon is not running yet")}
}
return nil
}, 2*time.Second)
}
2 changes: 1 addition & 1 deletion pkg/crc/preflight/preflight_daemon_task_check_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func fixDaemonTaskRunning() error {
logging.Debugf("unable to run the %s task: %v : %s", constants.DaemonTaskName, err, stderr)
return err
}
return nil
return waitForDaemonRunning()
}

func checkIfOlderTask() error {
Expand Down

0 comments on commit 21adefa

Please sign in to comment.