From 3c27f598bb909adf6d12ba9cbd6a135d263e9615 Mon Sep 17 00:00:00 2001 From: Sven Rebhan <36194019+srebhan@users.noreply.github.com> Date: Tue, 14 Sep 2021 15:31:44 +0200 Subject: [PATCH] fix: Update gopcua library to latest version (#9560) --- go.mod | 2 +- go.sum | 4 ++-- plugins/inputs/opcua/opcua_client.go | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 54d8eea5e..a05a8f5fa 100644 --- a/go.mod +++ b/go.mod @@ -121,7 +121,7 @@ require ( github.com/google/uuid v1.2.0 // indirect github.com/googleapis/gax-go/v2 v2.0.5 // indirect github.com/googleapis/gnostic v0.4.1 // indirect - github.com/gopcua/opcua v0.1.13 + github.com/gopcua/opcua v0.2.0-rc2.0.20210409063412-baabb9b14fd2 github.com/gorilla/mux v1.7.3 github.com/gorilla/websocket v1.4.2 github.com/gosnmp/gosnmp v1.32.0 diff --git a/go.sum b/go.sum index 1cc02dab3..b8002a55b 100644 --- a/go.sum +++ b/go.sum @@ -819,8 +819,8 @@ github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTV github.com/googleapis/gnostic v0.4.0/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU= github.com/googleapis/gnostic v0.4.1 h1:DLJCy1n/vrD4HPjOvYcT8aYQXpPIzoRZONaYwyycI+I= github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg= -github.com/gopcua/opcua v0.1.13 h1:UP746MKRFNbv+CQGfrPwgH7rGxOlSGzVu9ieZdcox4E= -github.com/gopcua/opcua v0.1.13/go.mod h1:a6QH4F9XeODklCmWuvaOdL8v9H0d73CEKUHWVZLQyE8= +github.com/gopcua/opcua v0.2.0-rc2.0.20210409063412-baabb9b14fd2 h1:OtFKr0Kwe1oLpMR+uNMh/DPgC5fxAq4xRe6HBv8LDqQ= +github.com/gopcua/opcua v0.2.0-rc2.0.20210409063412-baabb9b14fd2/go.mod h1:a6QH4F9XeODklCmWuvaOdL8v9H0d73CEKUHWVZLQyE8= github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= github.com/gophercloud/gophercloud v0.12.0/go.mod h1:gmC5oQqMDOMO1t1gq5DquX/yAU808e/4mzjjDA76+Ss= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= diff --git a/plugins/inputs/opcua/opcua_client.go b/plugins/inputs/opcua/opcua_client.go index 53454ba88..8dec41eb3 100644 --- a/plugins/inputs/opcua/opcua_client.go +++ b/plugins/inputs/opcua/opcua_client.go @@ -406,10 +406,10 @@ func Connect(o *OpcUA) error { o.state = Connecting if o.client != nil { - if err := o.client.CloseSession(); err != nil { + if err := o.client.Close(); err != nil { // Only log the error but to not bail-out here as this prevents // reconnections for multiple parties (see e.g. #9523). - o.Log.Errorf("Closing session failed: %v", err) + o.Log.Errorf("Closing connection failed: %v", err) } } @@ -445,8 +445,10 @@ func Connect(o *OpcUA) error { } func (o *OpcUA) setupOptions() error { + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(o.ConnectTimeout)) + defer cancel() // Get a list of the endpoints for our target server - endpoints, err := opcua.GetEndpoints(o.Endpoint) + endpoints, err := opcua.GetEndpoints(ctx, o.Endpoint) if err != nil { return err }