Skip to content

Commit

Permalink
[rpc] Run the probe first
Browse files Browse the repository at this point in the history
The previous beheavior of ProbeForever was to try a probe and then sleep for the `probeInterval` duration. When it was modified to use a `time.Ticker` instead of a sleep, it changed the behavior to wait the `probeInterval` first and then do the probe. This commit restore the previous behavior by running the probe first. Based on https://stackoverflow.com/a/54752803.
  • Loading branch information
Fricounet committed May 30, 2024
1 parent 856c5da commit a8003ad
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions rpc/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,32 @@ func ProbeForever(ctx context.Context, conn *grpc.ClientConn, singleProbeTimeout
defer ticker.Stop()

for {
// Run the probe once before waiting for the ticker
logger.Info("Probing CSI driver for readiness")
ready, err := probeOnce(ctx, conn, singleProbeTimeout)
if err != nil {
st, ok := status.FromError(err)
if !ok {
// This is not gRPC error. The probe must have failed before gRPC
// method was called, otherwise we would get gRPC error.
return fmt.Errorf("CSI driver probe failed: %s", err)
}
if st.Code() != codes.DeadlineExceeded {
return fmt.Errorf("CSI driver probe failed: %s", err)
}
// Timeout -> driver is not ready. Fall through to sleep() below.
logger.Info("CSI driver probe timed out")
} else {
if ready {
return nil
}
logger.Info("CSI driver is not ready")
}
select {
case <-ctx.Done():
return ctx.Err()
case <-ticker.C:
logger.Info("Probing CSI driver for readiness")
ready, err := probeOnce(ctx, conn, singleProbeTimeout)
if err != nil {
st, ok := status.FromError(err)
if !ok {
// This is not gRPC error. The probe must have failed before gRPC
// method was called, otherwise we would get gRPC error.
return fmt.Errorf("CSI driver probe failed: %s", err)
}
if st.Code() != codes.DeadlineExceeded {
return fmt.Errorf("CSI driver probe failed: %s", err)
}
// Timeout -> driver is not ready. Fall through to sleep() below.
logger.Info("CSI driver probe timed out")
} else {
if ready {
return nil
}
logger.Info("CSI driver is not ready")
}
continue
}
}
}
Expand Down

0 comments on commit a8003ad

Please sign in to comment.