Skip to content

Commit

Permalink
Run device manager outside of the error group (#2158)
Browse files Browse the repository at this point in the history
The device manager library doesn't support passing a context, hence it
can't be canceled by the error group.
To avoid blocking Odiglet in case of a fatal error, the device manager
is changed to run in a "regular" goroutine.
  • Loading branch information
RonFed authored Jan 8, 2025
1 parent 0168951 commit a90e163
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions odiglet/odiglet.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func New(deviceInjectionCallbacks instrumentation.OtelSdksLsf, factories map[com

// Run starts the Odiglet components and blocks until the context is cancelled, or a critical error occurs.
func (o *Odiglet) Run(ctx context.Context) {
ctx, cancel := context.WithCancel(ctx)
g, groupCtx := errgroup.WithContext(ctx)

if err := o.criClient.Connect(ctx); err != nil {
Expand All @@ -108,11 +109,16 @@ func (o *Odiglet) Run(ctx context.Context) {
// Start device manager
// the device manager library doesn't support passing a context,
// however, internally it uses a context to cancel the device manager once SIGTERM or SIGINT is received.
g.Go(func() error {
// We run it outside of the error group to avoid blocking on Wait() in case of a fatal error.
go func() {
err := runDeviceManager(o.clientset, o.deviceInjectionCallbacks)
log.Logger.V(0).Info("Device manager exited")
return err
})
if err != nil {
log.Logger.Error(err, "Device manager exited with error")
cancel()
} else {
log.Logger.V(0).Info("Device manager exited")
}
} ()

g.Go(func() error {
err := o.ebpfManager.Run(groupCtx)
Expand Down

0 comments on commit a90e163

Please sign in to comment.