Skip to content

Commit

Permalink
initialize context at client create
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed Feb 8, 2024
1 parent f9c0b04 commit 3e8f7f9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugins/inputs/opcua_listener/subscribe_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (sc *SubscribeClientConfig) CreateSubscribeClient(log telegraf.Logger) (*Su
return nil, err
}

processingCtx, processingCancel := context.WithCancel(context.Background())
subClient := &SubscribeClient{
OpcUAInputClient: client,
Config: *sc,
Expand All @@ -99,6 +100,8 @@ func (sc *SubscribeClientConfig) CreateSubscribeClient(log telegraf.Logger) (*Su
// the same time. It could be made dependent on the number of nodes subscribed to and the subscription interval.
dataNotifications: make(chan *opcua.PublishNotificationData, 100),
metrics: make(chan telegraf.Metric, 100),
processingCtx: processingCtx,
processingCancel: processingCancel,
}

log.Debugf("Creating monitored items")
Expand Down Expand Up @@ -178,7 +181,6 @@ func (o *SubscribeClient) StartStreamValues(ctx context.Context) (<-chan telegra
}
}

o.processingCtx, o.processingCancel = context.WithCancel(context.Background())
go o.processReceivedNotifications()

return o.metrics, nil
Expand Down

0 comments on commit 3e8f7f9

Please sign in to comment.