Skip to content

Commit

Permalink
fix: adjust connection for custom gRPC trigger
Browse files Browse the repository at this point in the history
`grpc.NewClient` does not automatically connect to the gRPC server
anymore. This is unlike the previously used `grpc.Dial`[1].

This change reintroduces initial connection test.

[1]: https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md

Signed-off-by: Michael Weibel <[email protected]>
  • Loading branch information
mweibel committed Jan 10, 2025
1 parent 23367d3 commit be125dd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/sensors/triggers/custom-trigger/custom-trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,25 @@ func NewCustomTrigger(sensor *v1alpha1.Sensor, trigger *v1alpha1.Trigger, logger
opt...,
)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to connect to trigger server: %w", err)
}

backoff, err := sharedutil.Convert2WaitBackoff(&sharedutil.DefaultBackoff)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to convert wait backoff: %w", err)
}

if err = wait.ExponentialBackoff(*backoff, func() (done bool, err error) {
logger.Debugw("waiting for trigger client connection...", "server-url", ct.ServerURL, "err", err, "state", conn.GetState().String())
if conn.GetState() == connectivity.Idle {
conn.Connect()
}
if conn.GetState() == connectivity.Ready {
return true, nil
}
return false, nil
}); err != nil {
return nil, err
return nil, fmt.Errorf("failed to connect to trigger server: %w", err)
}

customTrigger.triggerClient = triggers.NewTriggerClient(conn)
Expand Down

0 comments on commit be125dd

Please sign in to comment.