Skip to content

Commit

Permalink
conf: reduce readiness file stat() initial interval
Browse files Browse the repository at this point in the history
Sometimes even if the readiness file exists the os.Stat() call will
return "file not found". This causes GetReadinessIndicatorFile() to
wait 1 second during performance critical operations, even if the
os.Stat() would have returned success quickly after the first
failure.

Add a short backoff up to 1.2s before falling back to the longer
intervals. The exponential backoff shouldn't add too much stress
to the filesystem, but should allow quicker detection of the
readiness file on each container operation.

Signed-off-by: Dan Williams <[email protected]>
  • Loading branch information
dcbw committed Sep 12, 2023
1 parent 2053f6b commit 4be8d0f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/types/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,21 @@ func CheckSystemNamespaces(namespace string, systemNamespaces []string) bool {

// GetReadinessIndicatorFile waits for readinessIndicatorFile
func GetReadinessIndicatorFile(readinessIndicatorFile string) error {
// Quick first backoff up to ~1 second
backoff := utilwait.Backoff{
Steps: 5,
Duration: 75 * time.Millisecond,
Factor: 2.0,
Jitter: 0.1,
}
if utilwait.ExponentialBackoff(backoff, func() (bool, error) {
_, err := os.Stat(readinessIndicatorFile)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
return err == nil, nil
}) == nil {
return nil
}

// Otherwise wait a longer time until the file exists
pollDuration := 1000 * time.Millisecond
pollTimeout := 45 * time.Second
return utilwait.PollImmediate(pollDuration, pollTimeout, func() (bool, error) {
Expand Down

0 comments on commit 4be8d0f

Please sign in to comment.